I'm making a program that prints a triangle of @ signs given rows (but not columns). For example, the output with rows = 4 would be:
@@@@
@@@
@@
@
and rows = 3 would be:
@@@
@@
@
However, trying to make this has given me a program that does something similar (but not the same): for example, with my current program rows = 4 outputs:
@@@@
@@@
@@
@
and rows = 3 gives
@@@
@@
@
It seems that it's just missing a space (and therefore a setw and setfill), but I found 2 problems:
1. The space needs to not apply to the first line.
2. I can't get it to make a space before each row without making a space between each column.
My current code is:
#include <iostream>
#include <iomanip>
usingnamespace std;
int main ( ) {
int rows;
cout << "How many rows? ";
cin >> rows;
cout << endl;
for(int r = 0; r < rows; r++) {
for(int c = rows; c > r; c--) {
cout << "@";
}
// cout << setw(r);
cout << endl;
// cout << setw(r);
}
}
I have tried putting in << setws and << setfills of various values but it seems to always apply to between each column as well as at the start of each row- what do I do?
To me, it's fine if you copy 'n paste, AS LONG AS YOU STUDY THE ANSWER, and UNDERSTAND why it does, what it does. And not copy for sake of just getting an answer. And it seems to me, you DO want to learn. Very good!!