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 << " ").
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.
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.
Well it would be a hell of a lot easier if you chose meaningful variable names.
1 2 3 4 5 6 7
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";
}