Page 1 of 1

C Programming: Percentages; A Calculation question

PostPosted: Sat Oct 09, 2004 3:14 am
by Just4Fun
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. :wink: TIA

PostPosted: Sat Oct 09, 2004 12:42 pm
by makslane
- Declare percentA, percentB, percentC, percentD, percentF as double
- printf( "\t\tB: %d\t%f%c\n",bCount, percentB,'%');

PostPosted: Sun Oct 10, 2004 1:45 am
by Just4Fun
Makslane,

You solved my problem perfectly. I certainly respect your ability as a programmer.

Thank you for your help and all of the support that you give to me and to all of the members of the GameEditor community.

If I could ever meet you, I would ask for your autograph! :wink: