please help

Could someone help me with my hw here is the problem i have and the code "In this exercise, you create a program that uses two nested loops to display two different patterns of
asterisks: Pattern 1 contains nine rows of asterisks as follows: nine asterisks, eight asterisks, seven
asterisks, six asterisks, five asterisks, four asterisks, three asterisks, two asterisks, and one asterisk . Pattern 2 contains nine rows of asterisks as follows: one asterisk, two asterisks, three
asterisks, four asterisks, five asterisks, six asterisks, seven asterisks, eight asterisks, and nine asterisks."
I have the first part done and i need help to add a "do while" loop

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  #include <iostream>
using namespace std;

int main()
{
	int line;
	int numAstericks;

	for (int line = 1;line <= 9; line += 1)
	{
		for (int numAstericks = 1; numAstericks <= line; numAstericks += 1)
			cout << '*';
			//endfor
			cout << endl;
	}


	system("pause");
	return 0;
}
Last edited on
Try this
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
using namespace std;

int main()
{
    for(int i = 9; i >= 0; --i){
        for(int ast = 0; ast < i; ast++){
            cout << "*";
        }
        cout << endl;
    }
    
    for(int i = 1; i <= 9; ++i){
        for(int ast = 1; ast <= i; ast++){
            cout << "*";
        }
        cout << endl;
    }
	return 0;
}
*********
********
*******
******
*****
****
***
**
*

*
**
***
****
*****
******
*******
********
*********
Last edited on
Is there anyway you could do a “do while” loop with it?
yes, but you have to update the incremental value in the for loop so that if it is 0 it turns from -1 to +1.
You go down from 9 to 0 and back form 0 to 9 (do while iterator <=9).
Topic archived. No new replies allowed.