hello - an upside down triangle

hello , i am trying to program for school an upside down triangle .
so far succeded but have some problem with it.
first one is that the rows of the triangle goes like this : (exp- 5,3,1)
and not 5,4,3,2,1.
second one is that when i tried to make boundries {} to the loops (for)
the code changes to a different thing than it was without the boundries {}



i would like to have help with it .
thank you all .

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

  #include <iostream>
using namespace std;

void main()
{
	int num;

	cout << "Enter a number" << endl;
	cin >> num;


	for (int rows = num;  rows > 0;  rows = rows - 2)
	{
		for (int spaces = 0; spaces < (num - rows) / 2; spaces++)
		{
			cout << " ";
		}
		for (int stars = 0; stars < rows; stars++)
				cout << "*";
				cout << endl;
			
	}


system("pause");

}


Last edited on
This is the correct way to do it. There is nothing wrong with this except that main should return int and not void.
Topic archived. No new replies allowed.