Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. C programming Determine Students grade

C programming Determine Students grade

Scheduled Pinned Locked Moved C / C++ / MFC
css
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 12809618
    wrote on last edited by
    #1

    Write a program that determines a student's grade. It reads three test scores(between 0 and 100) and calls a function that calculates and returns a student's grade based on the following rules: A. If the average score is 90% or more, the grade is A. B. If the average score is 70% or more and less than 90%, it checks the third score. If the third score is more than 90%, the grade is A; otherwise, the grade is B. and it continues... The program's main is to contain only call statements. At least three subfunctions are required: one to read scores, one to determine the grade, and one to print the results. This is what I have so far but it will not run for me. I am not allowed to use global declarations.

    #include <stdio.h>

    // Function Declarations

    int main (void)
    {
    // Local Declarations
    int score1, score2, score3;
    char grade;
    int temp = 0;

    // Statements
    printf("Enter the test score (0-100): ");
    scanf ("%d", &score1);
    printf("Enter the test score (0-100): ");
    scanf ("%d", &score2);
    printf("Enter the test score (0-100): ");
    scanf ("%d", &score3);

        printf("The grade is: %c\\n", score1, score2, score3);
    
        return 0;
    

    } // main

    /* =================== scoreToGrade ===================
    This function calculates letter grade for a score.
    Pre the parameter score
    Post returns the grade
    */

    // Local Declarations
    int temp = 0;
    {
    temp = (score1+score2+score3)/3;

    // Statements
    if (score >= 90)
    grade = 'A';
    else
    if (score >= 80)
    grade = 'B';
    else
    if (score >= 70)
    grade = 'C';
    else
    if (score >= 60)
    grade = 'D';
    else
    grade = 'F';

    char grade;

    // Statements
    if (score >= 90)
    grade = 'A';
    else
    if (score >= 80)
    grade = 'B';
    else
    if (score >= 70)
    grade = 'C';

    L 1 Reply Last reply
    0
    • U User 12809618

      Write a program that determines a student's grade. It reads three test scores(between 0 and 100) and calls a function that calculates and returns a student's grade based on the following rules: A. If the average score is 90% or more, the grade is A. B. If the average score is 70% or more and less than 90%, it checks the third score. If the third score is more than 90%, the grade is A; otherwise, the grade is B. and it continues... The program's main is to contain only call statements. At least three subfunctions are required: one to read scores, one to determine the grade, and one to print the results. This is what I have so far but it will not run for me. I am not allowed to use global declarations.

      #include <stdio.h>

      // Function Declarations

      int main (void)
      {
      // Local Declarations
      int score1, score2, score3;
      char grade;
      int temp = 0;

      // Statements
      printf("Enter the test score (0-100): ");
      scanf ("%d", &score1);
      printf("Enter the test score (0-100): ");
      scanf ("%d", &score2);
      printf("Enter the test score (0-100): ");
      scanf ("%d", &score3);

          printf("The grade is: %c\\n", score1, score2, score3);
      
          return 0;
      

      } // main

      /* =================== scoreToGrade ===================
      This function calculates letter grade for a score.
      Pre the parameter score
      Post returns the grade
      */

      // Local Declarations
      int temp = 0;
      {
      temp = (score1+score2+score3)/3;

      // Statements
      if (score >= 90)
      grade = 'A';
      else
      if (score >= 80)
      grade = 'B';
      else
      if (score >= 70)
      grade = 'C';
      else
      if (score >= 60)
      grade = 'D';
      else
      grade = 'F';

      char grade;

      // Statements
      if (score >= 90)
      grade = 'A';
      else
      if (score >= 80)
      grade = 'B';
      else
      if (score >= 70)
      grade = 'C';

      L Offline
      L Offline
      leon de boer
      wrote on last edited by
      #2

      You need to hit the books or web lessons on C again. Your 3 statement inputs look good ... sorry that is it :-) Your printf statement is garbage hit the web or books and look up the words "formatted output of printf" and look at what %c means. However you have done absolutely nothing with the inputs to even think about calling that. What we are saying is you need to call a function between the last input and trying to print anything ... so

      scanf ("%d", &score3);

      //... You need a function call in here to do something with the scores and then fix the print below

      printf("The grade is: %c\n", score1, score2, score3);

      You even have the text that boldly says "// Function declarations" only you don't have anything there you just drop straight into main. Let me guess that was a hint in the template they gave you and you don't even get what it means? ScoreToGrade which was obviously was intended as your function is hanging out way down the bottom. You need to either forward declare it where you boldly declare you are going to have "// Function declatations" or move it up to there. So it's a cut and paste job or look up how to forward declare a prototype. Final problem

      // Local Declarations
      int temp = 0;

      It says it is local it is in fact a global variable ... you need to work out why.

      In vino veritas

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups