+ 2
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++; }
7 odpowiedzi
+ 3
Inside the body of the loop, after getting the user's input, add this block
if (number == 5) break;
Happy ending all around! 8D
+ 6
Remove = in the while.. It should help.. 😅
while(num<5)
+ 3
Any chance you wrongly put
cin >> num;
instead of
cin >> number;
in the body of the loop?
+ 1
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 )
+ 1
yes, thank you soldier :)
+ 1
int count = 0;
int number;
for (int i = 0; i < 4; i++) {
cin >> number;
if (number == 5) {
break;
}
if (number <= 5) {
count++;
}
0
Then, how to make this code end when the user input (5) at the first time?