# Help!! My last project of the year!! I'm almost done

• 12-01-2010
dmeyers81
Help!! My last project of the year!! I'm almost done
I have this function in a separate file to be called in the main program. I know that i have to have a for statement under the first one where i already figured the sum. Please help.

Code:

//----------------------------------------------------------------------------- // deviation function // //-----------------------------------------------------------------------------         #include <cmath>         double deviation(double list[], int size)         {                 double total=0;                 double average;                 double S;                 double U;                 double sum;                                 for(int x = 0; x<size; x++){                         total += list[x];                 }                 average = total/size;                 for(                 S = (sqrt (U / size));                 return S;         }
• 12-01-2010
Salem
So what do you need - the sum of square roots of each list[x] ?

You already have a for loop dealing with list[x].
If that is what you need to do again, what is the problem?
• 12-01-2010
dmeyers81
i found the average already but i need to figure the standard deviation of the array.
• 12-01-2010
Salem
So is this a math question then?

Maybe do a google search for "How to calculate standard deviation"
• 12-02-2010
dmeyers81
Its a question of how do i write it in c++
• 12-02-2010
Salem
calculate standard deviation - Google Search

From Wikipedia
1. Find the mean, \scriptstyle\overline{x}, of the values.
2. For each value \scriptstyle x_i calculate its deviation \scriptstyle x_i \,-\, \overline{x} from the mean.
3. Calculate the squares of these deviations.
4. Find the mean of the squared deviations. This quantity is the variance σ2.
5. Take the square root of the variance.
You've done step 1, now try step 2.