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
5 Posts 5 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.
  • H Offline
    H Offline
    hoangtrungl
    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

    OriginalGriffO J D B 4 Replies Last reply
    0
    • H hoangtrungl

      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

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      You don't show what you have so far, so we can't really give you any explicit help. But ... if you can't use global declarations, then you need to use local variables and parameter passing. That means you write your functions to accept the data they are to work on, and return values to the caller. For example:

      int sum (int* data, int count)
      {
      int i;
      int total = 0;
      for (i = 0; i < count; i++)
      {
      total += *data++;
      }
      return total;
      }
      ...
      int main()
      {
      int result;
      int data[100];
      int i;
      for (i = 0; i < 5; i++)
      {
      data[i] = i + 1;
      }
      result = sum(data, 5);
      printf("%u\n", result);
      }

      Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      1 Reply Last reply
      0
      • H hoangtrungl

        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

        J Offline
        J Offline
        Jochen Arndt
        wrote on last edited by
        #3

        This requires to use variables to hold the scores and the grade. If you are not allowed to use global variables you must declare them in your main() function and pass them to the functions:

        int main()
        {
        int grade;
        int score1, score2, score2;

        ReadScores(&score1, &score2, &score3);
        grade = GetGrade(score1, score2, score3);
        PrintGrade(grade);
        return 0;
        

        }

        hoangtrungl wrote:

        The program's main is to contain only call statements.

        I would read that in the sense of that it should not contain any operations but that variable declarations, assignment, and the mandatory return statement are allowed. [EDIT] After thinking about it a while I found a solution that does not use any variables in main():

        int main()
        {
        PrintGrade(GetGrade(ReadScores()));
        return 0;
        }

        Then ReadScores() must return a structure containing the data (which may be optionally dynamically allocated) that is passed to GetGrade() (which can free allocated memory) which returns the grade that is passed to the Print() function. [/EDIT]

        1 Reply Last reply
        0
        • H hoangtrungl

          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

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          hoangtrungl wrote:

          This is what I have so far...

          :confused:

          "One man's wage rise is another man's price increase." - Harold Wilson

          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

          "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

          1 Reply Last reply
          0
          • H hoangtrungl

            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

            B Offline
            B Offline
            Bram van Kampen
            wrote on last edited by
            #5

            Hmm Ah, it is that time of the year again. This looks suspiciously like an examination project. There are various reasons why this forum does not do these. For one, most people on this forum have already passed their exams, while many others earned their feathers trough self study and hard graft. Furthermore we would not like to contribute to the creation of qualified software engineers who mis the basic concepts.(as you seem to do). You don't actually show what you have. (maybe you don't know how to, if so, follow the posting guidelines on this site.) Show me yours, and I'll show you Mine. :)

            Bram van Kampen

            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