In C++11/14, a
return
statement is not required in
main
.
In the
for
loop where you receive a new value for
b
from the standard input on each iteration, you actually replace the previous value with the new value given by
cin
which may come as a surprise.
You're not adding the new value to
b
, you're completely obliterating the previous value of
b
and then you assign a new value as specified by your input.
When the
for
loop finally terminates 5 iterations later, the value of b is the last value provided by the standard input. So if the input is
the value of
b
will be 3.
Since
average
is an integer, the result of
b/5
will be truncated to the first integral digit. i.e, if
b
is 12, the result will not be 2,4 but 2.
To fix this you should change
average
's type to
double
.
Now you have enough information to solve it by yourself.