Pages

Sunday, September 01, 2013

Write a program that convert score to grade in C++

This program reads a test score .Calculate the letter grade based on the absolute scale, and print it

Source Code:


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
   #include <iostream.h>
   #include <conio.h>
   
   char scoreToGrade (int score);
   
   int main ()
      {
       cout << " Enter the test score(0-100): ";
       int score;
       cin  >> score ;
       
      char grade = scoreToGrade (score);
      cout << " The grade is: " << grade << endl;
      getch();
      return 0;
             } //main
   /* ============= scoreToGrade ===================
   This function calculates the letter grade for a score
   Pre  the parameter score
   Post Return the grade                     */
   char scoreToGrade (int score)
   {
    char grade;
   
   
        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';
   getch ();
   return grade;    
                }// scoreToGrade 

Result:


 Enter the test score (0-100): 91
 The grade is: A

No comments:

Post a Comment