ok, so im writing a program to have the user enter an amount of students, have the user type the grade for the # of students, then output and calcualate the mean, standard deviation with functions... after that you must print out the grade, also in a function, with the letter grades equaling a formula... here's my code, i got the mean and standard deviation correctly, but the grades are wrong. any help would be appreciated. thanks.
These are the formulas used to get the grades...
Code:
//x=Numeric score(grd[s])
//m=displaymn
//sigma=displaystddev
//x < m - 3/2(sigma) --> F
//m - 3/2(sigma) <= x < m - 1/2(sigma) --> D
//m - 1/2(sigma) <= x < m - 1/2(sigma) --> C
//m + 1/2(sigma) <= x < m + 3/2(sigma) --> B
//m + 3/2(sigma) <= x --> A
this is my code....
#include<iostream.h>
#include<iomanip.h>
#include<math.h>
//function prototypes
double mean(int[],int,int);
double stddev(int[],int,int);
void dispgrds(int[],int,int);
int main()
{//Top of main
int grd[100],x,y;
cout<<"Enter number of students\n";
cin>>x;
cout<<"Enter"<<' '<<x<<' '<<"grades\n";
for(y=0;y<x;y++)
cin>>grd[y];
cout.setf(ios::fixed,ios::floatfield);
cout.setf(ios::showpoint);
cout.precision(1);
//print-out of mean
cout<<"MEAN:";
cout<<mean(grd,x,y)<<endl;
//print-out of standard deviation
cout<<"STANDARD DEVIATION:";
cout<<stddev(grd,x,y)<<endl;
//print-out of grades
cout<<"GRADES:";
dispgrds(grd,x,y);
return 0;
}//bottom of main
//function header for function mean
double mean(int grd[],int i,int j)
{
double sum=0,avg=0;
for(i=0;i<j;i++)
sum+=grd[i];
avg=sum/j;
return avg;
}
//function header for function stddev
double stddev(int grd[],int a, int b)
{
double sum2=0,avg2=mean(grd,a,b);
for(a=0;a<b;a++)
sum2+=(grd[a]-avg2)*(grd[a]-avg2);
avg2=sum2/b;
return sqrt(avg2);
}
//function header to print grades
void dispgrds(int grd[], int s, int t)
{
double displaymn=mean(grd,s,t),displaystddev=stddev(grd,s ,t);
for (s=0; s<t; s++)
if (grd[s] < displaymn - (3/2 * displaystddev))
cout << 'F'<<' ';
else if (grd[s] >= displaymn - (3/2 * displaystddev) && grd[s] < displaymn - (1/2 * displaystddev))
cout << 'D'<<' ';
else if (grd[s] >= displaymn - (1/2 * displaystddev) && grd[s] < displaymn + (1/2 * displaystddev))
cout << 'C'<<' ';
else if (grd[s] >= displaymn + (1/2 * displaystddev) && grd[s] < displaymn + (3/2 * displaystddev))
cout << 'B'<<' ';
else if (grd[s] >= displaymn + (3/2 * displaystddev))
cout << 'A' <<' ';
}