Asterisk design
I want to create an asterisk form like this
*
**
***
****
*****
and so on ..
I have done a code that looks like this
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
|
#include <iostream>
using namespace std;
int main()
{
int x , y;
char s;
s='\n';
x=0;
y=1;
while(x<10)
{
y=y+1;
cout<<s;
while (y<y+1)
{
cout<<"*";
y=y+1;
}
x=x+1;
}
cin.get();
return 0;
}
|
But when i run it , it outputs infinite asterisk's ...
Can you please help me , i am a begginer :)
y<y+1
is always true for all values of y so the loop will not stop.
Last edited on
Oh , thanks :D
Now i have done it succesfully..
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
|
#include <iostream>
using namespace std;
int main()
{
int x , y , a , z;
char s;
s='\n';
a=1;
x=0;
y=1;
cout<<"how many rows ???"<<endl;
cin>>z;
while(x<z)
{
y=1;
a++;
cout<<s;
while (y<a)
{
cout<<"*";
y++;
}
x=x+1;
}
cout<<'\n';
system("pause");
return 0;
}
|
Topic archived. No new replies allowed.