promotion image of download ymail app
Promoted

program should use loops to display all 6 patterns with one execution. Input from the keyboard: # of rows, # of asterisks in the first row?

...

1 to increment asterisks in each following row, or

-1 to decrement the number in following rows, or

0 to keep the same number as in the first row

#include <iostream>

#include <iomanip>

#include <string>

using namespace std;

int main()

{

cout << "HOMEWORK 5 PART 1" << endl;

for (int count = 1; count <= 6; count++)

{

int rows,

asterisks,

incre_or_decre;

int col = 1;

cout << endl << endl;

cout << "Enter the number of rows ";

cin >> rows;

cout << "Enter the number of asterisks in the first row ";

cin >> asterisks;

cout << "Enter 1 if you want *'s to increase on each row, "

<< "-1 for decrease, 0 for no increase ";

cin >> incre_or_decre;

for (int row=1; row <= rows; row++)

{

while (col <= asterisks)

{

cout << "*";

col++;

}

}

}

cout << "Programmer Name: " << endl;

system("pause");

return 0;

}

Update:

The first two patterns display. But the others don't.

*********

********

******

*

**

***

****

…….

Update 2:

all the patterns are pretty much some kind of triangle.

Update 3:

Inputs for patterns

Pattern: 1 2 3 4 5 6

rows: 1 1 10 20 10 20

asterisks: 10 20 1 1 10 20

incre/decre: 0 0 1 1 -1 -1

1 Answer

Relevance
  • EddieJ
    Lv 7
    1 year ago

    cin >> incre_or_decre;

    cout << endl;

    for (int row=1; row <= rows; row++) {

    for (int col=1; col <= asterisks; col++) cout << "*";

    asterisks += incre_or_decre;

    cout << endl;

    }

    }

    I suspect your input is wrong. You should list it in the way you would enter it (so, without the labels).

    • Commenter avatarLogin to reply the answers
Still have questions? Get your answers by asking now.