C Programming: Percentages; A Calculation question

Non-platform specific questions.

C Programming: Percentages; A Calculation question

Postby Just4Fun » 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. :wink: TIA
I've learned that I still have a lot to learn.

** Makslane == Genious **
Just4Fun
 
Posts: 524
Joined: Tue Jul 01, 2003 5:19 am
Location: USA: Washington State; West Coast
Score: 6 Give a positive score

Postby makslane » Sat Oct 09, 2004 12:42 pm

- Declare percentA, percentB, percentC, percentD, percentF as double
- printf( "\t\tB: %d\t%f%c\n",bCount, percentB,'%');
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby Just4Fun » Sun Oct 10, 2004 1:45 am

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:
I've learned that I still have a lot to learn.

** Makslane == Genious **
Just4Fun
 
Posts: 524
Joined: Tue Jul 01, 2003 5:19 am
Location: USA: Washington State; West Coast
Score: 6 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest