0

Guys i can't able to understand the concept

int num = 1; int number; int total = 0; while (num <= 5) { cin >> number; total += number; num++; } cout << total << endl; anyone pls explain me

6th Aug 2017, 2:12 PM
Akash
Akash - avatar
1 Odpowiedź
+ 5
num is initially 0. So while num is smaller or equals to 5, the program will prompt the user to input to number, then, this number will be added to total, which was originally 0. For each iteration, num is increased by 1. Hence, this loop will run for num = 0, 1, 2, 3, 4, 5 :- Which is 6 times. The user will have to input 6 times to number, and these 6 numbers will be added to total. In the end, the total is printed.
6th Aug 2017, 2:17 PM
Hatsy Rei
Hatsy Rei - avatar