For loops help

i need to create a program that produces an amount of stairs based on the number user inputs.
for example the stairs will look like this if the user enters 4 :
X
XX
XXX
XXXX

however im having difficulty doing this , here is my code so far:
#include<iostream>
#include"110ct.h"
#include<string>

using namespace std;

int main()
{
int a;


cout << " please enter a number dude\n";
cin >> a;

for( int i = 1 ; i<=a ; ++ i)
{
cout << "x" << endl;
for(int j= 1 ; j<=a; ++j)
{
//cout <<" x" << endl;
}
}

qin.get();
return 0;

}

is their anyway of achieving this ?
you'll need nested for loops, means do not separate them.

for example:
1
2
3
for( int i = 1 ; i<=a ; ++ i)
       for(int j= 1 ; j < i; ++j)
             cout << //... 
Here's your code, modified with some comments:
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
#include<iostream>
#include"110ct.h" //You don't need this
#include<string> //You don't need this

using namespace std;

int main()
{
    int a;

    cout << " please enter a number dude\n";
    cin >> a;

    for( int i = 1 ; i<=a ; ++ i)
    {
//        cout << "x" << endl;    // This will only output one x per line
        for(int j= 1 ; j<=i; ++j) // replace 'a' with 'i' here, so we only write the number of Xs required. Not N Xs every line.
        {
        cout <<"X"; // Uncommented, you were on the right track here.
                    // I took the endl out of here so that you don't put a new line EVERY time you write " x"
        }
        cout << endl; // endl only when you have written all of the Xs on that line.
    }

    cin.get(); //cin, not qin.
    return 0;
}


Hopefully this helps your understanding;
Last edited on
Topic archived. No new replies allowed.