- 1
plz... any one explain this this is my humble requiest
int num = 1; int number; int total = 0; while (num <= 5) { cin >> number; total += number; num++; } cout << total << endl;
3 Answers
+ 5
What is your request?
+ 13
int num = 1;
int number;
int total = 0;
while (num <= 5) {
cin >> number;
total += number;
num++;
}
cout << total << endl;
// num is initially 1, and loop runs while num <= 5, so the loop body will run for num values 1, 2, 3, 4 and 5, that is, 5 times.
// in loop body, user input to number, and the number is added to total for each loop.
// after the loop is completed, the program outputs total, which is the sum of five user input