0

Partially understand loop. I'm confused.

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

9th Mar 2019, 1:31 PM
Micah Eckford
Micah Eckford - avatar
1 Answer
0
In my mind, it looks like I enter a number, say 5, and it keeps adding 5 to your number 5 times. But why? What I'm seeing is you add total (0) to your number (5). Is it num++ that makes it add your input to itself five times? if so, how if num is already declared to be 1 and '++' adds one to it?
9th Mar 2019, 1:34 PM
Micah Eckford
Micah Eckford - avatar