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

17th Aug 2017, 12:49 AM
ROSHAN SHETTY
ROSHAN SHETTY - avatar
3 Answers
+ 5
What is your request?
17th Aug 2017, 12:50 AM
Manual
Manual - avatar
+ 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
17th Aug 2017, 1:06 AM
Hatsy Rei
Hatsy Rei - avatar