Thread: a grading program

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    3

    a grading program

    Since this is my first post i would like to introduce myself, my name is Mike and i am currently a computer science student in michigan. We have to take a c programming class as our first programming class and we unfortunately got stuck with a very difficult to understand teacher who doesn't help us fix our programs he just tells us they are wrong. I will never come on here looking for someone to write my code just a nudge in the right direction as to why certain things aren't working.

    The current program i am working on is a fairly simple grading program that looks at the student grade input and assigns a grade. then prints the grade. The one problem i am having is that the main() can only contain calls to other functions. here is what i have so far.

    Code:
    #include <stdio.h>
    
    int ingrade();
    char gradedec();
    char gradeout();
    
    int main()
    {
        ingrade();
        gradedec(int grade3, int gradeavg, int gradeavgl);
        gradeout(char grade);
        
    }
    int ingrade()
    {
        int grade1;
        int grade2;
        int grade3;
        int gradeavg;
        int gradeavgl;
        printf("Please enter your three test scores:");
        scanf("%d %d %d",&grade1,&grade2,&grade3);
        gradeavg = (grade1+grade2+grade3)/3;
        gradeavgl=(grade2+grade3)/2;
        return gradeavg;
        return grade3;
        return gradeavgl;
    }
    char gradedec(int grade3,int gradeavg,int gradeavgl)
    {
        char grade;
        
         if(gradeavg>=90)
                 {
                         grade='A';
                 }    
         if(gradeavg<90,gradeavg>70)
                 {
                                    if(grade3>90)
                                                {
                                                       grade='A';
                                                }
                                    if(grade3<90)
                                                 {
                                                       grade='B';
                                                 }
                 }   
          if(gradeavg>50,gradeavg<70)
                 {
                                     if(gradeavgl>70)
                                     {
                                                     grade='c';
                                     }
                                     else
                                         grade='D';
                 }
           if(gradeavg<50)
           {
                          grade='F';
           }
           return grade;
    }
    char gradeout()
    {
        printf("your current grade is:%d",grade);
        return 0;
    }
    the specific problem i seem to be having is transferring one variable from a function to another function or defining certain variables for certain functions for example the lines
    Code:
    gradedec(int grade3, int gradeavg, int gradeavgl);
    gradeout(char grade);
    I apologize to the moderator if this type of post isnt allowed, i read the rules and assumed since i was asking a specific question it would be ok, if not i understand.
    thank you,
    mike

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >teacher who doesn't help us fix our programs he just tells us they are wrong.
    You don't have to suffer teachers like that. If he refuses to help you, that's neglecting to do his job, and you can report him for it.

    >gradedec(int grade3, int gradeavg, int gradeavgl);
    >gradeout(char grade);
    You don't include the data types when calling a function, and it's generally a good idea for the variables that you use as arguments to be in scope. I'd expect your main to look like this:
    Code:
    #include <stdio.h>
    
    /*
      Read scores up to the limit, store the number of loaded scores in n
    */
    int load_scores ( int scores[], int limit, int *n );
    
    /*
      Given a list of scores, determine a letter grade and display it
    */
    void show_grade ( FILE *out, int scores[], int n );
    
    int main ( void )
    {
      int scores[3];
      int n;
    
      if ( load_scores ( scores, 3, &n ) ) {
        /* All scores were loaded */
        show_grade ( stdout, scores, n );
      }
    
      return 0;
    }
    Somehow I doubt your teacher wants you to work out a way to have only function calls (and no declarations) in main.
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Oct 2007
    Posts
    3
    thank you for your quick response. I moved my declarations to the main function. and now the program actually runs but i get the same output everytime, "119". I assumed i defined something wrong but if it was just an ASCII declaration 119 is "w" which i have no where in my code.

    any other input appreciated

    thanks
    mike

  4. #4
    Gentoo System .......... Doorsdown's Avatar
    Join Date
    May 2007
    Location
    Rhode Island, USA
    Posts
    19
    http://www.google.com/search?hl=en&q...=Google+Search <-- for the ascii tables

    this would be a nice neat way of doing your program

    Code:
    #include <stdio.h>
    
    char gradedec(int);
    
    int main()
    {
            int grade1, grade2, grade3;
    
            printf("Please enter your three test scores: ");
            scanf("%d %d %d",&grade1,&grade2,&grade3);
            printf("Your Class Grade is %c.\n",gradedec((grade1+grade2+grade3)/3));
    
            return 0;
    }
    
    char gradedec(int average)
    {
            if(average>=90)
                    return 'A';
            else if(average>=80)
                    return 'B';
            else if(average>=70)
                    return 'C';
            else if(average>=65)
                    return 'D';
            else
                    return 'F';
    }
    heres the output

    Code:
    ryan@slayer ~ $ gcc grade.c
    ryan@slayer ~ $ ./a.out
    Please enter your three test scores: 70 80 90
    Your Class Grade is B.
    ryan@slayer ~ $
    Last edited by Doorsdown; 10-15-2007 at 09:59 PM.

  5. #5
    Registered User
    Join Date
    Oct 2007
    Posts
    3
    you guys are awesome, and please dont get me wrong im looking more so for why my code isnt working not the solution.
    Code:
    #include <stdio.h>
    
    int ingrade();
    char gradedec();
    char gradeout();
    
    int main()
    {
      
        int grade1;
        int grade2;
        int grade3;
        int gradeavgl;
        char grade;
    
        ingrade();
        gradedec(int gradeavg,int gradeavgl,int grade);
        gradeout();
    
    
        return 0;
        
    }
    int ingrade(int gradeavg,int grade3,int gradeavgl,int grade2,int grade1)
    {
        
        printf("Please enter your three test scores:");
        scanf("%d %d %d",&grade1,&grade2,&grade3);
        gradeavg = (grade1 + grade2 + grade3)/3;
        gradeavgl=(grade2+grade3)/2;
        return gradeavg;
        return grade3;
        return gradeavgl;
    	return grade1;
    	return grade2;
    }
    char gradedec(int gradeavg,int gradeavgl,int grade)
    {
    	int grade
        
         if(gradeavg>=90)
                                    grade='A';           
         else if(gradeavg<=90,gradeavg>=70)
    	 {
                                    if(grade3>90)
                                         return 'A';
                                                
                                    else if(grade3<90)
    									return 'B';
                 }   
          else if(gradeavg>=50,gradeavg<=70)
                 {
                                     if(gradeavgl>70)
                                                    return 'C';
                                     
                                     else if(gradeavgl<70)
                                         return 'D';
                 }
           
           else 
                return 'F';
           ;
    }
    gradeout(grade)
    {
        printf("your current grade is:%c", gradedec);
        return 0;
    }
    any input, anything that even would get me closer is greatly appreciated.

    thanks,
    mike

  6. #6
    Gentoo System .......... Doorsdown's Avatar
    Join Date
    May 2007
    Location
    Rhode Island, USA
    Posts
    19
    ok, your function gradeout, in your declaration you have it returning a char but when you use it you pass it a char

    Code:
    char gradeout()
    gradeout(grade)
    {
        printf("your current grade is:&#37;c", gradedec);
        return 0;
    }
    when you have a function that return a int like this, if you just put avg(myarray) in your code the returning result won't go any where.

    Code:
    int avg(int nums[])
    {
        int avg = 0, i = 0;
        while(nums[i]!='\0')
        {
            avg += nums[i++];
        }
        return (avg/i);
    }
    
    
    avg(myNums); //wrong
    int result = avg(myNums); //correct

  7. #7
    Registered User
    Join Date
    Jan 2007
    Location
    Euless, TX
    Posts
    144
    This works:

    Code:
    #include <stdio.h>
    
    void ingrade();
    char gradedec();
    void gradeout();
    
    int grade1 = 0;
    int grade2 = 0;
    int grade3 = 0;
    int gradeavgl = 0;
    int gradeavg = 0;
    char grade = 'X';
    
    int main()
    {
      
        ingrade();
    
        printf("GRADE1 = %d  GRADE2 = %d   GRADE3 = %d\n", grade1,grade2,grade3);
    
        grade = gradedec(gradeavg, gradeavgl, grade);
        gradeout(grade);
    
    
        return 0;
        
    }
    void ingrade()
    {
        
        printf("Please enter your three test scores:");
        scanf("%d %d %d",&grade1,&grade2,&grade3);
    
        printf("Your 3 scores are %d  %d  %d\n", grade1, grade2, grade3);
    
        gradeavg = (grade1 + grade2 + grade3)/3;
        printf ("GRADEAVG = %d\n", gradeavg);
        gradeavgl=(grade2+grade3)/2;
        printf ("GRADEAVGL = %d\n", gradeavgl);
    //    return gradeavg;
    //    return grade3;
    //    return gradeavgl;
    //	 return grade1;
    //	 return grade2;
    }
    char gradedec(int gradeavg,int gradeavgl,char grade)
    {
        
         if(gradeavg >= 90)
            grade='A';           
         else if(gradeavg<90 && gradeavg >= 80)
      		  grade = 'B';
         else if(gradeavg < 80 && gradeavg <= 70)
            grade = 'C';
         else if(gradeavgl < 70 && gradeavgl>= 60)
            grade = 'D';
         else 
            grade = 'F';
         
         printf("YOUR GRADE IS %c\n", grade);
         return grade;
    }
    void gradeout(char grade)
    {
        printf("your current grade is: %c", grade);
    }

  8. #8
    Gentoo System .......... Doorsdown's Avatar
    Join Date
    May 2007
    Location
    Rhode Island, USA
    Posts
    19
    yes but it heavily depends on global variables which for the most part is frowned upon as it works here but it could cause lots of trouble in a bigger program

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 11:17 PM
  2. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 10:58 PM
  3. Grading Program
    By hockeydrummer88 in forum C++ Programming
    Replies: 6
    Last Post: 03-09-2005, 12:05 PM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM