View Single Post
pichlo's Avatar
Posts: 6,445 | Thanked: 20,981 times | Joined on Sep 2012 @ UK
#10
Doing something even just twice is good enough a reason to make it a loop. 2 is a special case of N. If your assignment calls explicitly for doing it twice, unlikely as it sounds, then I would still write it as a loop that runs twice.

But enough of that, now to your averages. What is an average? A sum of all inputs divided by their number. Your assignment does not require to remember all the ratings, only the average. So you need just three variables. One temporary for reading the input, one for holding the sum of the inputs and one for holding their number. So get rid of MPAARating (it is not used anywhere) and replace numRate[5] with just two numbers, one for the sum and one for the number. Initialize both to 0, then each time the user enters a rating, add the rating to the sum and add 1 to the number. At the end, divide the sum with the number.
 

The Following User Says Thank You to pichlo For This Useful Post: