How to display rows of asterisk, incrementing or decrementing, with user input?

Full Disclosure this is a HW assignment. But I already turned it in last night so I'm sure I got a d or c. I just want learn know how to do this correctly.

The assignment is to create a program that displays 6 patterns with one execution. Our prof gave us the input info and how it should look like if done correctly. The first two patterns came out correctly b/c they only have one row of asterisks. But once I get to the third pattern it comes out all wrong. The input for the 3rd pattern is: rows: 10, asterisks: 1, incre_or_decre: 1.

Goal: My goal is to get the third pattern to display correctly. It should display with 1 asterisk in the first row and increment with each row with the last row being the 10th row (like a right triangle of asterisks). Instead what is displayed is just one of row of 10 asterisks.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
  int main()
{
    cout << "HOMEWORK 5 PART 1\n";

    for (int count = 1; count <= 6; count++)
	{
		int rows,
		asterisks,
		incre_or_decre;

		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++)
		{
		     for (int col=1; col <= asterisks; col++)
                         cout << "*";  
			
		}
	}
}
Last edited on
This should produce something interesting.
1
2
3
4
	     for (int col=1; col <= asterisks; col++) {
                         cout << "*";  
	     }
	     asterisks += incre_or_decre;
Registered users can post here. Sign in or register to post.