Let me start by saying this code is excellent. It is very well formatted and very clear, and the things I mention below are all extremely minor. Fantastic work.
That said, here are some things I noticed. And again I want to emphasize that these things are very minor and I am
really nitpicking here:
1) ArrayInput should probably take a maximum size as a 2nd parameter. As it stands now, if the user inputs more than 50 values, your program will corrupt memory and do 'Very Bad Things'
tm
2) The variable names in your ArraySum function are questionable. The name should reflect what the variable represents:
- SumOfNumbers is a fine name.
(Personally I would have went with 'sum' because it's just as clear but is less typing. But whatever. SumOfNumbers is great.) The problem is, your array is named 'Addition' ... so why isn't it named 'SumOfAddition'? Or better yet, why isn't your array called 'Numbers'? After all, it is an array of numbers, it's not an array of addition.
- Input is no longer input, but is the size of the array. 'size' would be a much more appropriate name.
- 'idle' is a little weird. It's clearly a loop counter and loop counters usually don't have informative names (typically they're just a 1 letter name like
i
) so it's not that big of a deal. But why 'idle'? What about it is idle? Just seems strange.
3) Same problem with 'input' in main.
First it is the size of the data, then it's the sum of the data. At no point does that variable contain input -- so calling it input doesn't really make sense.
4) Same problem with 'input' in ArrayInput. 'count' would be a better name since it's a count of how many numbers have been input... and isn't actually the input itself.
5) You can use the += operator on line 52 to shorten it:
1 2 3 4 5
|
// this:
SumOfNumbers = Addition[idle] + SumOfNumbers;
// is the same as this:
SumOfNumbers += Addition[idle];
|
6) Line 27 is a little weird. Why in parenthesis? And why not just initialize input when you create it like you do with SumOfNumbers on line 48?