### asterisks in a form of triangles I am trying to write a program that prints asterisks in a form of triangles. I would like to print 4 different triangles. I managed to do the first two. I would like to do two more triangles, these should be the vertical mirror image of the first two triangles (right justified, but I would like to do it with cout << " ").

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859`` `````` #include #include using namespace std; int main(){ unsigned int x; unsigned int y; unsigned int o{1}; for(x=1; x<=10; x++){ cout << "\n"; for(y=o; y>=1; y--){ cout << "*"; } o++; } cout << "\n"; unsigned int n{10}; for(x=1; x<=11; x++){ cout << "\n"; for(y=n; y>=1; y--){ cout << "*"; } n--; } unsigned int p{10}; for(x=1; x<=10; x++){ cout << " " << "\n"; for(y=p; y>=1; y--){ cout << "*"; } p--; } cout << "\n"; unsigned int u{1}; unsigned int f{1}; for(x=1; x<=10; x++){ cout << "\n"; for(y=u; y>=1; y--){ cout << "*"; } u++; } } `````` This is a basic exercise for understanding nested loops. You are doing okay, except for the printing part.

Remember, you need to print not just asterisks, but spaces.

It helps to get out a piece of graph paper and a pencil and draw what you want to see, treating each square cell of the paper as a character cell of your terminal.

Good luck! Yes, I got that, I need to put spaces before the asterisks. If I do it with another for statement it will be in a separate row and I can`t put the spaces with the asterisks in a cout statement neither. That is the closest result I have got so far. Please if anyone has an idea how I can make those triangles. Please help me.

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061`` `````` #include #include using namespace std; int main(){ unsigned int x; unsigned int y; unsigned int o{1}; for(x=1; x<=10; x++){ cout << "\n"; for(y=o; y>=1; y--){ cout << "*"; } o++; } cout << "\n"; unsigned int n{10}; for(x=1; x<=11; x++){ cout << "\n"; for(y=n; y>=1; y--){ cout << "*"; } n--; } cout << "\n"; for(x=1; x<=10; x++){ for(y=1; y<=x; y++){ if(x==y){ cout << "*"; } else{ cout << " "; } } cout << "\n"; } cout << "\n"; for(x=10; x>=1; x--){ cout << "\n"; for(y=1; y<=x; y++){ cout << "*"; } } } `````` Well it would be a hell of a lot easier if you chose meaningful variable names.
 ``1234567`` ``````for ( int row = 0 ; row < 5 ; row++ ) { int numOfLeadingSpaces = .... int numOfStars = .... for ( int c = 0 ; c < numOfLeadingSpaces ; c++ ) cout << " "; for ( int c = 0 ; c < numOfStars ; c++ ) cout << "*"; cout << "\n"; }``````