Now that you have the average, you again loop through the array, comparing each element to that average.
vmanes
Posting Virtuoso
1,914 posts since Aug 2007
Reputation Points: 1,268
Solved Threads: 228
What's giving you problems?
You already have a loop that visits each element:
for (int i = 0; i < 8; i++)
sum+= array[i];
A lot of writing programs is just taking something that's been done and using it a bit differently.
So make a copy of that loop and change the body to do the new task. You'll probably want to do that as a couple statements - one to find the difference between the current array value and the average, and one to display that difference. So, fill in the blanks:
for (int i = 0; i < 8; i++)
{
}
And, when you post your solution, please wrap it with the code tags, like:[code]
your code
goes here
[/code]
This will make it more readable.
vmanes
Posting Virtuoso
1,914 posts since Aug 2007
Reputation Points: 1,268
Solved Threads: 228
Deviation usually implies subtraction. Subtract each element from the average (or vice versa).
I believe your assignment is to show how each array value differs from the average, so your summing of the differences is not what you want. Just display the difference (which will be + or - ) for each element.
What you're doing by accumulating a sum in the second loop is sort of on the path to calculating Standard Deviation of the whole set. Not part of your current problem, as I read it.
vmanes
Posting Virtuoso
1,914 posts since Aug 2007
Reputation Points: 1,268
Solved Threads: 228
Ohhhh, that hurts!
You should put all that tedious code into a loop, so you have only one line that calculates the dev, then displays it. Actually, you can do all of that in just one line - do the calculation in the spot where you're displaying dev.
vmanes
Posting Virtuoso
1,914 posts since Aug 2007
Reputation Points: 1,268
Solved Threads: 228