Thread: calculating gpa with only grades?

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    28

    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.

  2. #2
    Registered User
    Join Date
    Sep 2007
    Posts
    1,012
    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.

  3. #3
    Registered User
    Join Date
    Sep 2010
    Posts
    28
    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

  4. #4
    Just a pushpin. bernt's Avatar
    Join Date
    May 2009
    Posts
    426
    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.
    Consider this post signed

  5. #5
    Registered User
    Join Date
    Sep 2010
    Posts
    28
    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);
    }}

  6. #6
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    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.

  7. #7
    Registered User
    Join Date
    Sep 2010
    Posts
    28
    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.

  8. #8
    Registered User
    Join Date
    Sep 2010
    Posts
    28
    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

  9. #9
    Registered User
    Join Date
    Sep 2010
    Posts
    46
    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");
    }
    Last edited by askinne2; 11-03-2010 at 11:11 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Runtime problem
    By SantoshN in forum C Programming
    Replies: 2
    Last Post: 10-12-2010, 02:42 PM
  2. Replies: 16
    Last Post: 09-19-2009, 03:22 AM
  3. GPA Program Problems
    By Clint in forum C Programming
    Replies: 3
    Last Post: 04-28-2005, 10:45 AM
  4. Grades program has me lost
    By adrea in forum C++ Programming
    Replies: 3
    Last Post: 12-14-2002, 08:35 PM
  5. proofread my expos-ay
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 10-04-2002, 08:31 PM