Understanding Looping

Hello I'm new to C++. This is my second time writing a program.
I'm supposed to write this code where if i input an even number, a loop based triangle shows up and if i input an odd number, a different loop based triangle shows up. I got some help from a website and modified it for my needs and it works perfectly. The only problem is that I don't understand how it works.

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
32
33
34
35
36
37
  #include <iostream>

using namespace std;

int main()
{
    int input;
    cin >> input;
    if (input %2 == 0 && input > 0) {

  for( int i = 6; i >= 1; i-- )
  {
    for( int j = 1; j <= 6; j++)
    {
      cout << (j <= i ? "*" : " " );
    }
    cout << endl;
  }
  }

if (input %2 == 1 && input > 0 )
    {

  for( int i = 1; i <= 6; i++ )
  {
    for( int j = 1; j <= 6; j++)
    {
      cout << (j <= i ? "*" : " " );
    }
    cout << endl;
  }



   return 0;
}
}


why do i have two integers? why won't it work if i just put in i alone or j alone?

Thank you for your time.
Basically, the inner for loop is printing out the "*" while the outside loop allows the program to go to the next line for the inner loop to redo the process.
Think about what you're doing: you're printing a 2D triangle, so you need to keep track of both an X/row and Y/column coordinate.
I am going to sound dumb but I still don't get it.
Think of the outer loop being the row you are editing. As you get into a row, the inner loop will do something with that row (in this case print out a number of "*"). Once the inner loop is finished, the outer loop would then go to the next row and keep doing this until the outer loop is completed.
Topic archived. No new replies allowed.