I need help looping this

I need help looping this code so that is prompts the user to enter a number of rows again how many times the user would like to continue, I suck at loops and I've tried looking at other forums for help and just get more confused.

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
//libraries
#include <iostream>
using namespace std;

//global constants

//no functioning prototype

int main(){
    //Define variables
    int n; // Number of rows
    int i; // Row count in for loop
    int k; // Output for loop

    // Have user input n
    cout << "Enter number of rows: ";
    cin >> n;

    // Complete for loop
    for (i = 1; i <= n + 1; i++){
    for (k = 1; k < i; k++){
    if (k<i-1) cout << ' '; else cout << k <<endl;
  }

   
}
    system("PAUSE");
    return EXIT_SUCCESS;
}
Repeat until you input 0.

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
//libraries
#include <iostream>
using namespace std;

//global constants

//no functioning prototype

int main(){
    //Define variables
    int n; // Number of rows
    int i; // Row count in for loop
    int k; // Output for loop
do{
    // Have user input n
    cout << "Enter number of rows: ";
    cin >> n;

    // Complete for loop
    for (i = 1; i <= n + 1; i++){
    for (k = 1; k < i; k++){
    if (k<i-1) cout << ' '; else cout << k <<endl;
  }


}
}while(n!=0);
    system("PAUSE");
    return EXIT_SUCCESS;
}
Topic archived. No new replies allowed.