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; }
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.
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.