Completed
Apr 28, 2012 at 6:52pm UTC
Its done
Last edited on Apr 28, 2012 at 7:20pm UTC
Apr 28, 2012 at 7:15pm UTC
The program above you typed have only one problem, you are using = in second while loop, which is an assignment operator. You must use == in while loop which is a conditional operator.
But still your program doesn't give the output as you want at end.
check it out as below.
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
#include <iostream>
#include <string>
#include <conio.h> // added to pausa screen, used function getch() at end
using namespace std;
int main()
{
int i = 0;
int stars;
//5
//
cout << "how many stars?" << endl;
cin >> stars;
cout << "" << endl;
while (stars >= i)
{
cout << "*" ;
while (stars == i)
{
cout << "" << endl;
stars -= 1;
break ;
}
i+=1;
}
getch();// to pause screen when program ends
return 0;
}
The below program is right according to output sample you given.
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
#include <iostream>
#include <string>
#include <conio.h> // added to pausa screen, used function getch() at end
using namespace std;
int main()
{
int i = 0;
int stars;
//5
//
cout << "how many stars?" << endl;
cin >> stars;
cout << "" << endl;
while (stars > i)
{
int j=0;
while (j < stars)
{
cout << "*" ;
++j;
}
cout << endl;
--stars;
}
getch();// to pause screen when program ends
return 0;
}
and why you including string? I think there is no need of string in this program.
Last edited on Apr 28, 2012 at 7:17pm UTC
Topic archived. No new replies allowed.