# Thread: average in an array

1. ## average in an array

I'm trying to write a C++ program that prompts for 20 individual grades. Then I want to calculate the class average and then list the grades in the order they were entered and how many points (+ or -) the individual grade was from the average. I'm setting this up using an array. I'm not looking for the full code, I'm just stuck on the code to display the "(+ or -) the individual grade was from the average."

2. Well can you calculate the average or not?

Then it's simply
cout << score - average;

3. for those scores below average, subtracting average from score will be negative. If you want to be able to say "Current score is x points below average" rather than "current score is -x points", then you can do something like:

result = abs(score - average)

to show the difference whether it is higher or lower than the average (that is, the absolute value of the difference), or, if you aren't supposed to use abs(), or equivalent, you can roll your own by doing something like

assign score - average to result
if result is greater than zero
output results
otherwise
assign minus one times result to result
output results