Like Tree1Likes
  • 1 Post By tabstop

Gpa calculator any ideas

This is a discussion on Gpa calculator any ideas within the C Programming forums, part of the General Programming Boards category; i want my variable (j) to be various and make sure the loop runs from the point of view of ...

  1. #1
    Registered User
    Join Date
    Oct 2013
    Posts
    5

    Gpa calculator any ideas

    i want my variable (j) to be various and make sure the loop runs from the point of view of (j) which can be any number causing it to repeat any help ??!!
    and how would i go about making the module grade and id print the result with my function and a grade point value
    and also make it do calculation like Grade point value and total module credits 5 per subject...Which there are twelve

    Code:
    #include <stdio.h>
    Code:
    #include <stdlib.h>
    
    struct input{
        char fname[12];
        char lname[12];
        char studentid[10];
        char moduleid[10];
        float modulegrade;
    };
    void Grade(struct input data);
    void GPV(struct input data);
    
    int main()
    {
     int i,j;
     struct input words[120];
     struct input data[15];
    
    
     printf("*-----------Welcome To The GPA CALCULATOR----------*");
    
     printf("\n \nHow Many students would you like to enter: ");
     scanf("%d",&j);
    
    for(j=0;j<100;j++)
    
    
    {
    
        printf("\n\nEnter The First Name & Last Name & Student ID:\n");
        scanf("%s %s %s",words[j].fname,words[j].lname,words[j].studentid);
    
        for(i=0;i<12;i++)
        {
        printf("\n\nEnter The Module ID & Module Grade Achieved:\n");
        scanf("%s %f",data[i].moduleid,&data[i].modulegrade);
        }
    }
    
    Grade(data[i]);
    
    
    
    return 0;
    }
    void Grade(struct input data )
    {
    
    
        if ((data.modulegrade >80) &&(data.modulegrade <=100))
        {
            printf("A");
        }
        if ((data.modulegrade >70) &&(data.modulegrade <= 79))
        {
            printf("B+");
        }
        if ((data.modulegrade >60) &&(data.modulegrade <=69))
        {
            printf("B");
        }
        if ((data.modulegrade >55) &&(data.modulegrade <=59))
        {
            printf("B-");
        }
       if ((data.modulegrade >50) &&(data.modulegrade <= 54))
        {
            printf("C+");
        }
        if ((data.modulegrade >40) &&(data.modulegrade <= 49))
        {
            printf("C");
        }
        if ((data.modulegrade >35) &&(data.modulegrade <=39))
        {
            printf("D");
        }
        if (data.modulegrade <35 )
        {
            printf("F");
        }
       return ;
    }

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You can't use the same variable for "the number of total students" and "the # for the current student I'm working with". j is okay for the latter; you should probably use a more meaningful name (like num_students or similar) for the first.

    Currently you can only store one modulegrade for each student, so asking for 12 of them just means that 11 of them are going to be thrown away. Perhaps you want an array of those instead? (Same for module ID.)

  3. #3
    Registered User
    Join Date
    Oct 2013
    Posts
    5
    But I declared module I'd as character array,I could change j to a variable from before I called studamnt; , but how would I cause the stud amount to change depending on how many students intake and make it loop ?

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by Junior Aj Twist View Post
    But I declared module I'd as character array,I could change j to a variable from before I called studamnt; , but how would I cause the stud amount to change depending on how many students intake and make it loop ?
    If I have successfully translated this question to English, the answer is that j is just fine as it is. This line right here, however:
    Code:
    scanf("%d",&j);
    needs to send that typed-in number into some other variable other than j. You want j to go from 0 to <some number that gets typed in>, so you had better store <some number that gets typed in> in a variable that has a name that isn't j.

  5. #5
    Registered User
    Join Date
    Oct 2013
    Posts
    5
    So if I added

    int studamnt;

    And made it

    Printf("\n \nHow many students would you like to enter: ");
    Scanf("%d",&studamnt);

    How would this enable my loop to fire depending on my studamnt in respect
    To j

    Would I make studamnt a array?
    And make it &studamnt[j]
    In the scanf

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by Junior Aj Twist View Post
    So if I added

    int studamnt;

    And made it

    Printf("\n \nHow many students would you like to enter: ");
    Scanf("%d",&studamnt);

    How would this enable my loop to fire depending on my studamnt in respect
    To j
    That would work fine, because you can use j<studamnt as your stop condition in your for loop.

    Quote Originally Posted by Junior Aj Twist View Post
    Would I make studamnt a array?
    And make it &studamnt[j]
    In the scanf
    Why would you want it to be an array? The number of students is just that, a number; it's not a series of numbers.

    (If you mean that you want to input the number of classes instead of having i always go to 12, then that means you would need to store that number in your struct with the other information about your student.)

  7. #7
    Registered User
    Join Date
    Oct 2013
    Posts
    5
    Thanks a lot for helping me solve the varying problem mate , how would I go about
    The void GPV function
    How do I involve numbers of the grade point value in the module grade
    I'm working with floats of 4.00 downwards

    Would it make sense regarding my if statements to use a printf again for the GPV ?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. some ideas
    By kiwi101 in forum C Programming
    Replies: 34
    Last Post: 10-30-2012, 11:04 PM
  2. in need of some ideas and help....HELP!!!!
    By ccar033 in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 03:58 AM
  3. ANY IDEAS, would appreciate any help!
    By unejam2005 in forum C++ Programming
    Replies: 1
    Last Post: 12-04-2005, 01:11 AM
  4. job ideas
    By dP munky in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 04-19-2003, 02:42 AM
  5. Ideas
    By GodLike in forum Game Programming
    Replies: 5
    Last Post: 04-16-2002, 01:57 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21