Simple while QA | Sololearn: Learn to code for FREE!


Simple while QA

How can I modify this code to make it accept 4 entries <= 5? int num = 1; int number; while (num <= 5) { cin >> num; num++; }

11/10/2018 7:54:07 AM

Mohanad Methkal

6 Answers

New Answer


Inside the body of the loop, after getting the user's input, add this block if (number == 5) break; Happy ending all around! 8D


Remove = in the while.. It should help.. 😅 while(num<5)


Any chance you wrongly put cin >> num; instead of cin >> number; in the body of the loop?


No, maybe you do not understood me. if I run this code or even I remove = mark , the user stills can enter many numbers less than 5. But what I need is make this code allows to user to input just 5 entries ( if it was < 5 )


yes, thank you soldier :)


Then, how to make this code end when the user input (5) at the first time?