My program currently displays the mean and standard deviation of student marks. However, by default (since there are 2 records already with marks of 66 and 78.5), the standard deviation should be 6.25. However, on my program, it displays 1.5 instead.
Here are my codes:
Declarations in main():
1 2 3 4 5 6 7 8
int totalStudents=2;
float totalMarks;
float averageMark;
string id;
int found;
char studentGrade;
float stdDev;
float sum;
totalMarks=0;
sum=0;
for(int j=0;j<totalStudents;j++)
{//<-start of body of for cycle
totalMarks+=student[j].studentMark;
}//end of body
averageMark=totalMarks/totalStudents;
for(int j=0;j<totalStudents;j++)
{//first cycle was used to get the average
//you need a second one now:
sum+=pow(student[j].studentMark-averageMark,2);
}//you have to do the cycle twice mate: no way around that!
stdDev=sqrt(sum/totalStudents);
cout << "Number of records: " << totalStudents <<endl;
cout << "Mean or average: " << averageMark <<endl;
cout << "Standard deviation: " << stdDev <<endl;
//break;<- this line was plain wrong as helios pointed out