C Programming: Percentages; A Calculation question
Posted: Sat Oct 09, 2004 3:14 am
Do any of you programming aces know how to compute for an *accurate* percentile using C language syntax?
Assume that I have setup a program that enters student grades. At the program's end , I would like to print the percent of the grades earned in the class.
The code snippet that I'm using to solve the math is:
// calculate grade percentiles
percentA = (double)aCount/totalGradeCount*100;
percentB = (double)bCount/totalGradeCount*100;
percentC = (double)cCount/totalGradeCount*100;
percentD = (double)dCount/totalGradeCount*100;
percentF = (double)fCount/totalGradeCount*100;
//Print out the formated total of each grade entered
printf( "\t\tA: %d\t%d%c\n",aCount, (int)percentA,percentSign);
printf( "\t\tB: %d\t%d%c\n",bCount,(int)percentB,'%');
printf( "\t\tC: %d\t%d%c\n",cCount,(int)percentC,percentSign);
printf( "\t\tD: %d\t%d%c\n",dCount,(int)percentD,'%');
printf( "\t\tF: %d\t%d%c\n",fCount,(int)percentF,percentSign);
The problem is that my percentiles don't add up to 100%.
My print out looks like:
A: 3 25%
B: 2 16%
C: 3 25%
D: 2 16%
F: 2 16%
I know this isn't exactly GE stuff, but I'm wrestling with it so that I can learn better use of GE script editior. TIA
Assume that I have setup a program that enters student grades. At the program's end , I would like to print the percent of the grades earned in the class.
The code snippet that I'm using to solve the math is:
// calculate grade percentiles
percentA = (double)aCount/totalGradeCount*100;
percentB = (double)bCount/totalGradeCount*100;
percentC = (double)cCount/totalGradeCount*100;
percentD = (double)dCount/totalGradeCount*100;
percentF = (double)fCount/totalGradeCount*100;
//Print out the formated total of each grade entered
printf( "\t\tA: %d\t%d%c\n",aCount, (int)percentA,percentSign);
printf( "\t\tB: %d\t%d%c\n",bCount,(int)percentB,'%');
printf( "\t\tC: %d\t%d%c\n",cCount,(int)percentC,percentSign);
printf( "\t\tD: %d\t%d%c\n",dCount,(int)percentD,'%');
printf( "\t\tF: %d\t%d%c\n",fCount,(int)percentF,percentSign);
The problem is that my percentiles don't add up to 100%.
My print out looks like:
A: 3 25%
B: 2 16%
C: 3 25%
D: 2 16%
F: 2 16%
I know this isn't exactly GE stuff, but I'm wrestling with it so that I can learn better use of GE script editior. TIA