Thread: Help with calculating student GPA

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    23

    Help with calculating student GPA

    This is what I have right now, I need it to calculate and print the gpa but I have no clue on how to do it.

    The text document I am using has the following in it:
    Intro to Programming in C:4.5:3.67
    Intermediate Accounting:5:4.00

    Code:
    #include <stdio.h>
    #include <stdlib.h> 
    #include <ctype.h> 
    #include <iostream>
    
    
    void getchoice (void);
    void getinfo (void);
    
    int main (void)
    {
        int choice;
    
        getchoice ();
        return 0;
    }
    
    
    void getchoice (void)
    {
        int choice;
    
        do
        {
            printf ("Select where to print transcript: 1 to file or 2 to screen");
            scanf ("%d", &choice);
         
            if (choice == 1)
            {
                printf ("printing to file\n");
                
            }
            else if (choice == 2)
            {
                printf ("printing to screen\n");
                getinfo ();
            }
            else
            {
                printf ("please choose either 1 or 2");
            }
        }
        while (choice != 1 && choice != 2);
    }
    
    
    void getinfo (void)
    {
        FILE * in;
        FILE * out;
        float units;
        float gpa;
        char var;
    
        if ( (in = fopen ("record1.txt", "r")) == NULL)
        {
            printf ("error opening file");
            
        }
        while ((fscanf_s(in, "%c", &var)) != EOF)
        {
            printf ("%c", var);
            if (var == ':')
        {
        fscanf (in, "%f:%f", &units, &gpa);
        }
        }
    
        fclose (in);
    }



    This is the conversion table I came up with

    Code:
        if (gpa >= 3.99 && gpa <= 4.01)
            printf ("A");
        else if (gpa >= 3.66 && gpa <= 3.68)
           printf ("A-");
        else if (gpa >= 3.32 && gpa <= 3.34)
            printf ("B+");
        else if (gpa >= 2.99 && gpa <= 3.01)
             printf ("B");
        else if (gpa >= 2.66 && gpa <= 2.68)
            printf ("B-");
        else if (gpa >= 2.32 && gpa <= 3.34)
            printf ("C+");
        else if (gpa >= 1.99 && gpa <= 2.01)
            printf ("C");
        else if (gpa >= 1.66 && gpa <= 1.68)
             printf ("D+");
        else if (gpa >= 1.32 && gpa <= 1.34)
             printf ("D");
        else if (gpa >= 0.99 && gpa <= 1.01)
            printf ("D-");
        else
            printf ("F");

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by Magic staple View Post
    This is the conversion table I came up with
    Sheesh, there are some massive holes in that. What if I got a 4.2 GPA, or a 3.5? Etc.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by MK27 View Post
    Sheesh, there are some massive holes in that. What if I got a 4.2 GPA, or a 3.5? Etc.
    then you get an F, and that's your own fault :P

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. student looking for some help.
    By akairyuu in forum C++ Programming
    Replies: 5
    Last Post: 09-28-2009, 02:26 AM
  2. new student
    By monu in forum C Programming
    Replies: 5
    Last Post: 08-06-2007, 04:35 PM
  3. new student
    By monu in forum C Programming
    Replies: 3
    Last Post: 08-03-2007, 03:18 AM
  4. new student
    By monu in forum C Programming
    Replies: 2
    Last Post: 07-25-2007, 12:47 AM
  5. New C Student Needs Help
    By Flim Flam in forum C Programming
    Replies: 3
    Last Post: 06-08-2003, 11:47 AM