There are
two numbers of interest here:
- user input (and its sum)
- the loop counter
The loop executes
five times: num ← 1, 2, 3, 4, 5.
int num = 1;
while (num <= 5) {
num++;
The five inputs, whatever they are, are summed into total. They will sum to whatever you want; not necessarily a multiple of five.
The main problem here is the
bad variable names, which are all read by your human brain as "number", making it easy to confuse their relationship.
Here the program is rewritten a little:
- using better names
- putting related stuff together
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
#include <iostream>
using namespace std;
int main()
{
int user_input; // no need to guess what this is
int sum = 0; // or this
for (int n = 0; n < 5; n++) // the input counter is all in one spot
{
cin >> user_input;
sum += user_input;
}
cout << sum << "\n";
}
|
Hope this helps.