Helpful hints anyone?

This is a discussion on Helpful hints anyone? within the C Programming forums, part of the General Programming Boards category; Does anyone know how to complete this problem from my code that I have provided? I know it might not ...

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    14

    Angry Helpful hints anyone?

    Does anyone know how to complete this problem from my code that I have provided? I know it might not be allowed to post answers on this forum, but any pointers would be helpful, espeically regarding the section where it says "Only if the grade needs to be determined between D and F, allow the user to enter the number of homework assignments the student turned in, and the total number of homework assignments. If more than 80% of the homework assignments were turned in, the letter grade is D, otherwise F."

    Here's the problem:

    Write a program that determines a student's letter grade. Allow the user to enter three test scores. The maximum score on each test is 100 points. Determine the letter grade from the average of the test scores, using the following:

    * 90% or more A
    * 80% or more, but less than 90% B
    * 70% or more, but less than 80% C
    * 60% or more, but less than 70% D or F, to be determined from additional information
    * less than 60% F

    Only if the grade needs to be determined between D and F, allow the user to enter the number of homework assignments the student turned in, and the total number of homework assignments. If more than 80% of the homework assignments were turned in, the letter grade is D, otherwise F.

    Test it 4 times:

    * 96 84 90
    * 95 83 90
    * 70 59 60 with 4 homework out of 5 turned in
    * 73 58 65 with 8 homework out of 11 turned in
    Code:
    #include <stdio.h>
    
    // Function Declarations
    char scoreToGrade (int score, int score2, int score3);
    
    int main (void)
    {
        // Local Declarations
        int score;
        int score2;
        int score3;
        char grade;
        
        // Statements
        printf("Enter three test scores (0-100): ");
        scanf("%d", &score, &score2, &score3);
        
        grade = scoreToGrade (score, score2, score3);
        printf("The grade is: %c\n", grade);
        
        int temp;
        printf("Enter an integer and press Enter to exit the program: ");
        scanf("%d", &temp);
        
        return 0;
    }
    
    char scoreToGrade (int score, int score2, int score3)
    {
         // Local Declarations
         char grade;
         char temp;
         
         //Statements
         temp = score / 10;
         switch (temp)
         {
                case 10:
                case 9 : grade = 'A';
                         break;
                case 8 : grade = 'B';
                         break;
                case 7 : grade = 'C';
                         break;
                case 6 : grade = 'D';
                         break;
                default: grade = 'F';
                }
                return grade;
                }
    Thank you kindly.

  2. #2
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,689
    It says that getting a D has additional criteria. You have to change the grade to F if they missed more than 20% of their homework.

    That's just yet another percentage:


    Code:
    get homework completed
    get homework assigned
    
    if homework completed / homework assigned  < .80
       grade = F
    I used real numbers but you could probably do it with integers if you wanted.
    Last edited by whiteflags; 02-23-2011 at 12:09 AM.

  3. #3
    Registered User
    Join Date
    Feb 2011
    Posts
    14
    How would I implement that bit of code into the program to make it work? Sorry for not understanding.

  4. #4
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,689
    Sorry, I didn't write compilable C code. I think you know enough to take what I showed you as an example and write it out. If they could get a D, then compute the percentage, and decide if they get an F. I don't see a problem putting the actual code under the D grade case in your switch.

  5. #5
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,481
    Using whiteflags' pseudo code:
    Code:
                case 6 : 
                         get homework completed (get an integer from the user)
                         get homework assigned (get another integer from the user)
                         if homework completed / homework assigned  < .80
                             grade = 'F';
                         else
                             grade = 'D';
                         break;
    Also, you need to ask for all 3 scores, so you need 3 format specifiers for the scores you collect in main:
    Code:
        // Statements
        printf("Enter three test scores (0-100): ");
        scanf("%d %d %d", &score, &score2, &score3);

  6. #6
    Registered User
    Join Date
    Feb 2011
    Posts
    14
    Thanks for your help guys. Everything works now except for the fact that when the program is run, it automatically prints the default grade when any three grades are entered. Help on this?

    Code:
    #include <stdio.h>
    
    // Function Declarations
    char scoreToGrade (int score, int score2, int score3);
    
    int main (void)
    {
        // Local Declarations
        int score;
        int score2;
        int score3;
        char grade;
        
        // Statements
        printf("Enter three test scores (0-100): ");
        scanf("%d %d %d", &score, &score2, &score3);
        
        grade = scoreToGrade (score, score2, score3);
        printf("The grade is: %c\n", grade);
        
        int temp;
        printf("Enter an integer and press Enter to exit the program: ");
        scanf("%d", &temp);
        
        return 0;
    }
    
    char scoreToGrade (int score, int score2, int score3)
    {
         // Local Declarations
         char grade;
         char temp;
         int homework_completed;
         int homework_assigned;
         
         //Statements
         temp = (score + score2 + score3) / 10;
         switch (temp)
         {
                case 10:
                case 9 : grade = 'A';
                         break;
                case 8 : grade = 'B';
                         break;
                case 7 : grade = 'C';
                         break;
                case 6 : printf("Enter the number of homework assignments assigned: \n");
                         scanf("%d", &homework_assigned);
                         printf("Enter the number of homeowrk assignments completed: \n"); 
                         scanf("%d", &homework_completed);
                         if (homework_completed / homework_assigned  > .80)
                             grade = 'D';
                         else
                             grade = 'F';
                         break;
    
                default: grade = 'F';
                }
                return grade;
                }

  7. #7
    Registered User
    Join Date
    Feb 2011
    Posts
    14
    Nevermind. I got it

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Hints to write a program
    By Bnchs400 in forum C++ Programming
    Replies: 28
    Last Post: 04-05-2006, 05:35 AM
  2. Can you give me some hints?
    By mag_chan in forum C++ Programming
    Replies: 1
    Last Post: 12-04-2005, 01:12 AM
  3. newbie looking for hints on first audio program...
    By BrownB in forum Game Programming
    Replies: 2
    Last Post: 07-13-2005, 07:25 AM
  4. Hints required to complete simple programs
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 06-30-2002, 09:20 PM
  5. Need Delimiter Program helpful hints.
    By Unregistered in forum C Programming
    Replies: 7
    Last Post: 02-16-2002, 05:27 PM

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