# calculating gpa with only grades?

Printable View

• 11-01-2010
ashlee
calculating gpa with only grades?
is there some sort of calculation for just GPA without knowing the credits? i wrote a program which shows the average 20students have each after taking 3 exams each. now i must print the GPA of each student, as well as which has the highest GPA. i looked up some formulas via google search and didn't find much because the way GPA is calculated involves the credits taken.

Code:

```#include<stdio.h> int main() { float exam_a[20] = { 77, 65, 89, 79, 85, 90, 98, 45, 83, 75, 71, 85, 85, 80, 68, 72, 56, 82, 63, 80} ; float exam_b[20] = { 87, 92, 84, 89, 75, 99, 92, 66, 80, 77, 56, 79, 76, 78, 88, 78, 66, 70, 69, 90} ; float exam_c[20] = { 45, 77, 87, 77, 88, 83, 94, 71, 73, 83, 52, 80, 93, 88, 76, 64, 75, 80, 85, 52} ; int k; char letter; float student[20]; float sum_a = 0, sum_b = 0, sum_c = 0, sum_d = 0, sum_f = 0; int tot_a = 0, tot_b = 0, tot_c = 0, tot_d = 0, tot_f = 0; for (k = 0; k < 20; ++k){ sum_a = sum_a + exam_a[k]; student[k] = exam_a[k] + exam_b[k] + exam_c[k]; student[k] = (student[k])/3; if (student[k] >= 90){                 letter = 'A';                 ++tot_a;         }         else if (student[k] >= 80){                 letter = 'B';                 ++tot_b;         }         else if (student[k] >= 70)        {                 letter = 'C';                 ++tot_c;         }         else if (student[k] >= 60)        {                 letter = 'D';                 ++tot_d;         }         else        {                 letter = 'F';                 ++tot_f;     }         } printf("(Based on Averages)Number of As = %i \number of Bs = %i \number of Cs = %i \number of Ds = %i \number of Fs = %i \n", tot_a, tot_b, tot_c, tot_d, tot_f); }```
is to show which students got what grades on the average of 3 exams. i was thinking of maybe just doing if 95 and over store 4.0 90 and over store 3.7 and so on.. unless theres a better way to calculate this.
• 11-01-2010
cas
There is no universal grade-to-GPA calculator. Find a conversion table you like and use it.

You don't have to worry about credits. I don't know if your assignment states it, but you can certainly assume that all tests are weighted the same if it makes no mention otherwise. In that case, average the three tests and convert that to GPA however you want.

The “credits” part of a GPA calculation is simply for weighting different classes which have different credit hours. It's no different than an instructor saying something like “the first test is 20% of your grade, the second 30%, and the last 50%”, except it's on a class-by-class basis, not test-by-test.
• 11-01-2010
ashlee
is any calculation really necessary then? can something like

Code:

```if (student[k] >= 90){ printf("%i, 4.0 \n", k); } if (student[k] >= 80){ printf("%i, 3.5 \n", k); } if (student[k] >= 70){ printf("%i, 3.0 \n", k); } if (student[k] >= 60){ printf("%i, 2.0 \n", k); } if (student[k] >= 50){ printf("%i, 1.0 \n", k); }```
be done?
think im just lost on making a calculation for this
• 11-01-2010
bernt
Go ahead and try it out! Nothing's stopping you from experimenting on your own computer. :)

Make sure you get some upper limits for the GPA, though
Code:

`if (student[k] >=80 && student[k]<90)`
or at least have some else if's in the latter cases.
• 11-02-2010
ashlee
any idea why this shows no output?
Code:

```#include<stdio.h> int main() { float exam_a[20] = { 77, 65, 89, 79, 85, 90, 98, 45, 83, 75, 71, 85, 85, 80, 68, 72, 56, 82, 63, 80} ; float exam_b[20] = { 87, 92, 84, 89, 75, 99, 92, 66, 80, 77, 56, 79, 76, 78, 88, 78, 66, 70, 69, 90} ; float exam_c[20] = { 45, 77, 87, 77, 88, 83, 94, 71, 73, 83, 52, 80, 93, 88, 76, 64, 75, 80, 85, 52} ; int k; float student[20]; float sum_a = 0, sum_b = 0, sum_c = 0, sum_d = 0, sum_f = 0; int tot_a = 0, tot_b = 0, tot_c = 0, tot_d = 0, tot_f = 0; student[k] = exam_a[k] + exam_b[k] + exam_c[k]; student[k] = (student[k])/3; for (k = 0; k < 20; ++k){ } if (student[k] >= 95){ printf("%i, 4.0 \n", k); } else if (student[k] >= 90){ printf("%i, 3.5 \n", k); } else if (student[k] >= 85){ printf("%i, 3.3 \n", k); } else if (student[k] >= 80){ printf("%i, 3.0 \n", k); } else if (student[k] >= 75){ printf("%i, 2.7 \n", k); } else if (student[k] >= 70){ printf("%i, 2.5 \n", k); } else if (student[k] >= 65){ printf("%i, 2.3 \n", k); } else if (student[k] >= 60){ printf("%i, 2.0 \n", k); } else if (student[k] >= 55){ printf("%i, 1.7 \n", k); } else if (student[k] >= 50){ printf("%i, 1.5 \n", k); } else printf("%i, 1.0 \n", k); }}```
• 11-02-2010
stahta01
The if statement is after the for loop; do you think this is correct?

You for loop does very little since nothing is inside it.

Tim S.
• 11-02-2010
ashlee
yeah, when the } is taken out after the for loop i just get:

0, 2.3
1, 1.0
2, 1.0 and 1.0 for the rest of them up to 20.
• 11-03-2010
ashlee
any ideas? just cant get this to print. i want it to show.
First Student - GPA 4.0
Second Student - GPA 3.7
Third Student - GPA 2.0
-
-
Twentieth Student - GPA 1.0
• 11-03-2010
askinne2
You need to run the calculation of the grade for all k < 20. And here is working code for what you want. Please make sure you understand what it is doing and feel free to ask if you don't. Notice that I calculated the gpa using the formula: (gradeAverage / 100) * 4.0
Code:

```#include<stdio.h> #include<stdlib.h> int main() {     int exam_a[20] = { 77, 65, 89, 79, 85, 90, 98, 45, 83, 75, 71, 85, 85, 80, 68, 72, 56, 82, 63, 80} ;     int exam_b[20] = { 87, 92, 84, 89, 75, 99, 92, 66, 80, 77, 56, 79, 76, 78, 88, 78, 66, 70, 69, 90} ;     int exam_c[20] = { 45, 77, 87, 77, 88, 83, 94, 71, 73, 83, 52, 80, 93, 88, 76, 64, 75, 80, 85, 52} ;     int k;     double i;     int student[20];     double dStudent[20];         for(k = 0; k < 20; k++)     {         student[k] = exam_a[k] + exam_b[k] + exam_c[k];         student[k] = (student[k])/3;     }         for(k = 0; k < 20; k++)     {         dStudent[k] = (double)student[k];         i = (dStudent[k] / 100) * 4.0;         dStudent[k] = i;         printf("Student %d's grade: GPA of %.2lf\n", k+1, dStudent[k]);     }     system("PAUSE"); }```