0

Can any one please explain me this C++ code ......?

#include <iostream> using namespace std; int main() { int num = 1; int number; int total = 0; while (num <= 5) { cin >> number; total += number; } cout << total << endl; return 0; }

26th Mar 2020, 9:24 AM
Srivathsa Vollure
Srivathsa Vollure - avatar
2 Answers
+ 2
There is an issue with your loop. The loop will run infinite as the condition will remain true. So add num++; in the loop so that the loop stops executing after the condition is false.
26th Mar 2020, 9:29 AM
Taranjeet
Taranjeet - avatar
0
wait no no wait. ++num is what thou needeth. Looketh. The for loops gonna run (like FOREST GUMP). Can’t have it run. Can’t have it misbehave like that. Give a smack. Give it some DSCIPLINE.
26th Mar 2020, 10:47 AM
SappyB
SappyB - avatar