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

10th Aug 2016, 8:05 PM
Cazmir Raul-Alex
4 Respostas
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
10th Aug 2016, 9:01 PM
Nick
0
Yes, it go into an infinite loop, but why ? What i should to make to show just the values of a?
11th Aug 2016, 7:23 AM
Cazmir Raul-Alex
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
12th Aug 2016, 12:48 PM
Dmytro Petrenko
Dmytro Petrenko - avatar
0
bad
13th Aug 2016, 5:31 AM
Visionary Farru
Visionary Farru - avatar