Write a cpp program which displays the grade of a student when the score is entered.

I figured it out but I dont know how to make it return a plus symbol if a student just missed the next higher grade by one or two points(for example: if a student got an 88 or 89 this second output symbol should be '+'

Thank you very much


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
39
40
#include <cstdlib>
#include <iostream> 
using namespace std;


int main()
  {

       int score; //Displays the grade of a student when the score is entered.
       char grade;

       cout<<"\n Enter your score = "; // User input numeric vlue for grade
       cin>>score;     

       switch(score/10) //Stops at 100
      {
         case 10 :  grade='A'; //If enters 100 the grade will input A
            break;
                             
         case 9 :  grade='A'; //If enters between 90-100 the grade will input A
            break; 

         case 8 :  grade='B'; //If enters 80-89 the grade will input B
            break;

         case 7 :  grade='C'; //If enters 70-79 the grade will input C
            break;

         case 6 :  grade='D'; //If enters 60-69 the grade will input D
            break;

        
         default : grade='F'; //If enters anything below 60 the grade will be an F
      }

       cout<<"\n Your Grade is = "<<grade<<endl; //Gives score based on the numberic value entered
       system("Pause");
       return 0;
       
    }
Last edited on
if score + 2 / 10 doesn't equal score / 10, then you can assume a + ?
If for example I enter 80 i need to program to give me B- instead of just a B
Take score mod 10 to get the last digit of the score. Then compute the modifier from that. The code below returns a c-string:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
const char *getModifier (int score) {
    int modifier = grade % 10;  // modifier is 0-9
    switch (modifier) {
    case 0:
    case 1: 
    case 2: 
        return "-";
    case 8:
    case 9:
        return "+";
    default:
        return "";
    }
}


So how would i add that to the code all together to make it work.
 So how would i add that to the code all together to make it work.


before the main function
@lensalexis
PS:
use code tags: http://www.cplusplus.com/articles/jEywvCM9/
Topic archived. No new replies allowed.