+ 1
Anyone having trouble with their while(cin>>var)loops?
Don’t get to input the value for a second time. https://code.sololearn.com/cbbUd794sDLc/?ref=app
9 Respuestas
+ 5
This is a SoloLearn's specific. You must enter input once before execution and watch results. Try your code on real IDE
+ 4
So, yes. Code is correct
+ 4
What do you mean? It correctly parses input "0 0 0 7" and using negative nums cause same behavior
+ 3
And what do you what? Do you want to run code again for second positive integer within next line of input per one execution?
+ 1
Shouldn’t it be obvious I just want a while(cin>>var) loop to work properly? If the user keeps inputting non-positive integers, the code should ask them to keep inputting until they input a positive integer or non-integer value.
+ 1
It just doesn’t go as expected...
0
It doesn’t prompt me to enter another number if I give a non-positive one, it just ends the whole execution.
0
while statement expects to evaluate a true/non-zero-value or false/zero-value. What does (cin >> a) returns, if anything? Why not make it easier on yourself with the following:
while(true) {
cin >> a;
if (a < 0)
...
else
break;
}
0
Thank you guys.