Need help with program that prints a triangle of @ symbols

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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  #include <iostream>
#include <iomanip>
using namespace 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?
@keltonfan2

Is this the results you were after?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
include <iostream>
#include <iomanip>

using namespace std;

int main() 
{
	int rows;
	cout << "How many rows? ";
	cin >> rows;
	cout << endl;
	for (int r = 0; r < rows; r++)
	{

		for (int c = 0; c < rows; c++)
		{
			if (c < r)
				cout << " ";
			else
			  cout << "@";
		}
		cout << endl;
	}
}
Yes, however since this is for a homework assignment I can't copy and paste. I'll try to rewrite that and reply if I have any further problems :)

It's working, thanks.
Last edited on
@keltonfan2

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!!
Last edited on
Topic archived. No new replies allowed.