Anyone having trouble with their while(cin>>var)loops? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

11th Apr 2018, 10:41 AM
Jadenutt
Jadenutt - avatar
9 Answers
+ 5
This is a SoloLearn's specific. You must enter input once before execution and watch results. Try your code on real IDE
11th Apr 2018, 11:41 AM
Rull Deef 🐺
Rull Deef 🐺 - avatar
+ 4
So, yes. Code is correct
11th Apr 2018, 11:26 AM
Rull Deef 🐺
Rull Deef 🐺 - avatar
+ 4
What do you mean? It correctly parses input "0 0 0 7" and using negative nums cause same behavior
11th Apr 2018, 11:36 AM
Rull Deef 🐺
Rull Deef 🐺 - avatar
+ 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?
11th Apr 2018, 11:16 AM
Rull Deef 🐺
Rull Deef 🐺 - avatar
+ 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.
11th Apr 2018, 11:25 AM
Jadenutt
Jadenutt - avatar
+ 1
It just doesn’t go as expected...
11th Apr 2018, 11:28 AM
Jadenutt
Jadenutt - avatar
0
It doesn’t prompt me to enter another number if I give a non-positive one, it just ends the whole execution.
11th Apr 2018, 11:39 AM
Jadenutt
Jadenutt - avatar
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; }
11th Apr 2018, 11:53 AM
seetho
seetho - avatar
0
Thank you guys.
11th Apr 2018, 11:57 AM
Jadenutt
Jadenutt - avatar