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 '+'
#include <cstdlib>
#include <iostream>
usingnamespace 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;
}
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
constchar *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"";
}
}