This is quite good for a homework exercise.
I would recommend a for
loop instead of the while
:
for (int ValuesProcessed = 0; ValuesProcessed < ListSize; ++ValuesProcessed) {
This puts all the logic of iteration together where you are less likely to overlook
some detail, unlike the while
loop where the initial value of ValuesProcessed
,
the test for termination of the loop, and setting ValuesProcessed
for the next
iteration are done in three different places.
I tend to follow the philosophy of declaring things as close to where they are used
as possible, so I would move the declaration and initialization of ValueSum
after
the "Please enter" printout. But I don't think there's a strong argument for doing this.
(It would merely swap the order of two lines of code, not a big deal.)
Contrary to another answer, I like your decision to declare ListSize
in your main()
function. (It's another example of "declaring things as close to where they are used
as possible".) Although ListSize
is a "constant" in the sense that you have declared it
const
(which I think is a good idea), it is really just the end condition of a
single loop in the program, or to put it another way, the length of a list of inputs
that the program is about to read.