0
Why don't run me this program: #include<iostream> #include<cmath> using namespace std; int main() { int n, a, i; cout<<"n="; cin>>n; for(i=1;i<=n;i++) { cout<<"a="; cin>>a; do { cout<<"a="<<a; while(a!=0) } } cin.get(); system("Pause"); } and it's Visual Studio
4 Réponses
0
your "while(a!=0)" is inside the curly braces, move it to after them:
do
{
cout<<"a="<<a;
}while(a!=0)
but I think you should do a dry run of your program(on paper) as it will go into an infinite loop if people don't enter 0 for values of a
0
Yes, it go into an infinite loop, but why ? What i should to make to show just the values of a?
0
I think there is not needed loops. There is enough only one if operator in the end. like here:
int a;
cin>>a;
if(a!=0)
cout << "a = " << a;
because you use only one variable and enter n various for it. so at the end you will have the last value which you entered
0
bad