### Problem Coding Variance?!

Ok so my code compiles and runs, but the output of my variance is wrong. I'm brand new to coding and not sure how to code it correctly. For those who are not sure of the formula for variacne it goes as follows...

If the size of the set is 7 and the set is represented by X[0], X[1], X[2],
X[3],X[4], X[5], X[6], then the (biased) variance may be computed as:

variance = [(X[0]- mean)^2 +(X[1]-mean)^2 + ... +(X[6]- mean)^2]=7

 ``123456789101112131415161718192021222324252627282930313233343536`` ``````// This program calculates the sum, average, variance, and standard deviation of any numbers. // Using the for structure using namespace std; #include #include int main() { int n, count; double x, sum, avg, var, sd; sum = 0; cout << "How many numbers? "; cin >> n; int array[n]; for(count=0; count> array[n]; sum = sum + array[n]; } //end for for (count=1; count<=n; count++){ var = pow(array[n]-avg,2)/ (n); } avg = sum / n; sd= sqrt(var); cout << "The sum is " << sum << endl; cout << "The average is " << avg << endl; cout << "The variance is " << var << endl; cout << "The standard deviation is " << sd << endl; system("pause"); //Used so I can ready the outputs. return 0; //successful termination }//end main ``````
`var = pow(array[n]-avg,2)/ (n);`
1) Why is `/ (n)` here? it isn't in your formula. If you mistyped and there is /7 (instead of =7) then your code should be:
 ``12345`` ``````var = 0; for (count=0; count
Topic archived. No new replies allowed.