Can't get the right output..
Trying to calculate mean, standard deviation, & variance through data structures.
Output:
Mean: -9.25596e+061
Standard Deviation: 2.2836e+046
Variance: 5.21481e+092
Code:
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;
struct StatData
{
double Data[10];
double mean;
double stdDev;
double variance;
};
int main()
{
const int SIZE=10;
double sum=0;
double stdDevSum=0;
double temp=0;
int i=0;
int j=0;
StatData calc;
calc.Data[SIZE] = (24,21,24,43,31,41,42,34,41,45);
for(i=0;i<SIZE;i++)
sum=calc.Data[i]+sum;
calc.mean = sum/SIZE;
for(j=0;j<SIZE;j++)
stdDevSum = pow((calc.mean - calc.Data[j]),2) + stdDevSum;
temp = stdDevSum/SIZE;
calc.stdDev = sqrt (temp);
calc.variance = temp;
cout << "Mean: " << calc.mean << endl;
cout << "Standard Deviation: " << calc.stdDev << endl;
cout << "Variance: " << calc.variance << endl;
}