Like Tree1Likes
  • 1 Post By Elysia

Can anyone tell me what i did wrong? The program won't output the letter grade.

This is a discussion on Can anyone tell me what i did wrong? The program won't output the letter grade. within the C Programming forums, part of the General Programming Boards category; Code: #include <stdio.h> #include <stdlib.h> /* Author: Linda Source: Welcome program This program is to compute the output score, and ...

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

    Unhappy Can anyone tell me what i did wrong? The program won't output the letter grade.

    Code:
    #include <stdio.h> 
    #include <stdlib.h>
    
    /* 
    Author: Linda 
    Source: Welcome program   
    This program is to compute the output score, and the grade earned by the student.  
    Date: September 21, 2011 
    */
    
    int main(void) 
    {
        double gradeAsg1, gradeAsg2, gradeAsg3, gradeAsg4, gradeTest1, gradeTest2, gradeExam;
        double score;
        bool inRange;
        int grade; 
        
        printf("This program is to out the computed score, and the grade earned by the student.\n"); 
        printf("Enter Grade for assignment 1:");
        scanf("%d", &gradeAsg1);
        printf("Enter Grade for assignment 2:");
        scanf("%d", &gradeAsg2); 
        printf("Enter Grade for assignment 3:"); 
        scanf("%d", &gradeAsg3); 
        printf("Enter Grade for assignment 4:");
        scanf("%d", &gradeAsg4);
        printf("Enter Grade for Test 1:");
        scanf("%d", &gradeTest1);
        printf("Enter Grade for Test 2:");
        scanf("%d", &gradeExam); 
        
        score =(gradeAsg1+gradeAsg2+gradeAsg3+gradeAsg4)/400*0.2+(gradeTest1+gradeTest2)/200*0.4+gradeExam/100*0.4;
        
        printf("%d\n", score); 
          
        
    /*
        if ( score >=87 && score<=100 )
            inRange = true;
        else 
            inRange = false;
            
            */
        inRange=score >=87 & score <= 100;    
        if (inRange == true) printf ("A");  
        
        if ( score >= 74 && score<=87 )
            inRange = true;
        else
            inRange = false;
            
        if (inRange == true) printf("B"); 
        if ( score >= 61 && score<74 )
            inRange = true; 
        else 
            inRange = false; 
            
        if (inRange == true) printf("C"); 
        if( score >= 48 && score<61 ) 
            inRange = true;
        else 
            inRange = false;
            
        if (inRange == true) printf ("D"); 
        if ( score >= 0 && score<48) 
            inRange = true; 
        else 
            inRange = false; 
            
        if ( inRange == true) printf("F");
        printf("grade=%c\n",grade); 
         
        
        system( "Pause" );
        return 0;
        }

  2. #2
    Here we go again...
    Join Date
    Sep 2011
    Location
    San Diego
    Posts
    102
    You are using variables that haven't been given values yet:


    Code:
    printf("This program is to out the computed score, and the grade earned by the student.\n");      
    printf("Enter Grade for assignment 1:");     
    scanf("%d", &gradeAsg1);     
    printf("Enter Grade for assignment 2:");     
    scanf("%d", &gradeAsg2);      
    printf("Enter Grade for assignment 3:");      
    scanf("%d", &gradeAsg3);      
    printf("Enter Grade for assignment 4:");     
    scanf("%d", &gradeAsg4);     
    printf("Enter Grade for Test 1:");     
    scanf("%d", &gradeTest1);     
    printf("Enter Grade for Test 2:");     
    scanf("%d", &gradeExam);           
    
    score =(gradeAsg1+gradeAsg2+gradeAsg3+gradeAsg4)/400*0.2+(gradeTest1+gradeTest2)/200*0.4+gradeExam/100*0.4;          
    
    printf("%d\n", score);

  3. #3
    Registered User
    Join Date
    Oct 2011
    Posts
    6
    Oh, thanks! I fixed the variables, but it still won't ouput the letter grade

  4. #4
    Here we go again...
    Join Date
    Sep 2011
    Location
    San Diego
    Posts
    102
    Do you get any errors with your bool variable?

  5. #5
    Registered User
    Join Date
    Oct 2011
    Posts
    6
    No, i don't get any errors, but it still won't output the grade.

  6. #6
    Here we go again...
    Join Date
    Sep 2011
    Location
    San Diego
    Posts
    102
    try changing your double variables to floats and your scanf and print %d to %f

  7. #7
    Registered User
    Join Date
    Oct 2011
    Posts
    6
    I am using this program from the following website. Download Dev-C++ from SourceForge.net

  8. #8
    Registered User
    Join Date
    Oct 2011
    Posts
    6
    I try that but it didnt work. (

  9. #9
    Here we go again...
    Join Date
    Sep 2011
    Location
    San Diego
    Posts
    102
    This should do it for you...look at what I did and apply to your code.

    Code:
    #include <stdlib.h>
    #include <stdio.h>
    
    /* 
     Author: Linda 
     Source: Welcome program   
     This program is to compute the output score, and the grade earned by the student.  
     Date: September 21, 2011 
     */
    
    int main(void) 
    {
        int gradeAsg1, gradeAsg2, gradeAsg3, gradeAsg4, gradeTest1, gradeTest2, gradeExam;
        float score; 
        
        printf("This program is to out the computed score, and the grade earned by the student.\n"); 
        printf("Enter Grade for assignment 1:");
        scanf("%i", &gradeAsg1);
        printf("Enter Grade for assignment 2:");
        scanf("%i", &gradeAsg2); 
        printf("Enter Grade for assignment 3:"); 
        scanf("%i", &gradeAsg3); 
        printf("Enter Grade for assignment 4:");
        scanf("%i", &gradeAsg4);
        printf("Enter Grade for Test 1:");
        scanf("%i", &gradeTest1);
        printf("Enter Grade for Test 2:");
        scanf("%i", &gradeTest2); 
        printf("Enter Grade for Test 3:");
        scanf("%i", &gradeExam);
        
        float A1, A2, A3;
        A1 = ((gradeAsg1+gradeAsg2+gradeAsg3+gradeAsg4)/4)*0.2;
        A2 = ((gradeTest1+gradeTest2)/2)*0.4;
        A3 = (gradeExam)*0.4;
        score = A1 + A2 + A3;
        
        printf("Score: %.2f\n", score); 
        
        if (score >=87 && score<=100 )
            printf ("Grade: A\n");  
        if ( score >= 74 && score<=87 )
            printf("Grade: B\n"); 
        if ( score >= 61 && score<74 ) 
            printf("Grade: C\n"); 
        if( score >= 48 && score<61 )  
            printf ("Grade: D\n"); 
        if ( score >= 0 && score<48)  
            printf("Grade: F\n");
        
        return 0;
    }

  10. #10
    Registered User
    Join Date
    Oct 2011
    Posts
    6
    Thank you so much I really appreciate it

  11. #11
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,031
    Why is this on the C++ board?
    Salem likes this.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  12. #12
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,855
    Agreed - moved
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  13. #13
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by rmatze View Post
    This should do it for you...look at what I did and apply to your code.

    Code:
    #include <stdlib.h>
    #include <stdio.h>
    ...
    Now rmatze ... I'm guessing you think you just helped Linda out... and I note that she's even grateful.

    BUT... stop and ask yourself just how much did she learn by being handed the answer? (Especially one in a programming standard her compiler doesn't support.)
    Did she learn how to analyse the problem and put together code to solve it?
    Did she learn how to troubleshoot and fix code with problems?
    Did she learn anything new about C?

    Answer to all ... No.

    You may have put a smile on her face but in fact you did her no favours.

    Old proverb: "If you give a man a fish, you feed him for one day. If you teach a man how to catch fish, you feed his entire village for a lifetime."

    Ok... so how about we stop short circuiting people's educations...

  14. #14
    Here we go again...
    Join Date
    Sep 2011
    Location
    San Diego
    Posts
    102
    Noted.

    Quote Originally Posted by CommonTater View Post
    Now rmatze ... I'm guessing you think you just helped Linda out... and I note that she's even grateful.

    BUT... stop and ask yourself just how much did she learn by being handed the answer? (Especially one in a programming standard her compiler doesn't support.)
    Did she learn how to analyse the problem and put together code to solve it?
    Did she learn how to troubleshoot and fix code with problems?
    Did she learn anything new about C?

    Answer to all ... No.

    You may have put a smile on her face but in fact you did her no favours.

    Old proverb: "If you give a man a fish, you feed him for one day. If you teach a man how to catch fish, you feed his entire village for a lifetime."

    Ok... so how about we stop short circuiting people's educations...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. getting wrong output from simple program
    By d387420489 in forum C Programming
    Replies: 7
    Last Post: 07-28-2011, 07:21 PM
  2. Replies: 2
    Last Post: 01-29-2011, 12:58 PM
  3. Sorting student records by letter grade
    By holly14326 in forum C Programming
    Replies: 2
    Last Post: 07-27-2010, 08:49 PM
  4. Replies: 2
    Last Post: 03-05-2010, 02:59 AM
  5. Finding Letter Grade and Marital Status
    By ProgrammingDlux in forum C++ Programming
    Replies: 7
    Last Post: 03-28-2002, 12:05 AM

Tags for this Thread


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