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 ?
Something like this should work well enough

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
#include<iostream>

using namespace std;

int main()
{
	int Number;	
	int Amount = 1;

	cout << "Enter in how many 'stairs' you want" << endl;
	cin >> Number;

	for(int i = 0; i < Number; i++)
	{
		for(int j = 0; j < Amount; j++)
		{
			cout << "X";
		}

		cout << endl; 
		Amount +=1;   //Adds 1 'X' after every new line 
	}


	cin.ignore(); 
	cin.get();

	return 0;
}
Last edited on
This code will also do .

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
int main()
{
	int a =0 ;

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

	for( int i = 0 ; i<a ; ++ i)
	{
			cout << "x" << endl;
			for(int j= 0 ; j<=i; ++j)
			{
					cout <<" x" ;
			}
			cout<<"\n";
	}

qin.get();
return 0;

}
Topic archived. No new replies allowed.