So I have to write a program to calculate a grade letter into a number.
Letter grades are A, B, C, D, and F, possibly followed by + or â. Their numeric values are 4, 3, 2, 1, and 0. There is no F+ or Fâ. A + increases the numeric value by 0.3, a â decreases it by
0.3.
If the letter grade is illegal (such as "Z"), then your output should be "INVALID LETTER GRADE"; If the combination is illegal (such as "A+" or "F-") then your output should be "INVALID GRADE COMBINATION"
Also the code should look like this
Enter your letter grade: C+
Grade value is [2.3]
// Input
cout << "Enter your letter grade: ";
string s;
cin >> s;
string result = "Not processed";
double grade;
double a, A = 4;
double b, B = 3;
double c, C = 2;
double d, D = 1;
double f, F = 0;
if ((s >= "a" && s <= "f") || (s >= "A" && s <= "F"))
{
if (s == "a-" || s == "b+" || s == "b-" || s == "c+" || s == "c-" ||
s == "d+" || s == "d-" || s == "A-" || s == "B+" || s == "C+" ||
s == "C-" || s == "D+" || s == "D-")
{
}
else
{
result = "INVALID GRADE COMBINATION";
}
}
else
{
result = "INVALID LETTER GRADE";
}
// Output
cout << "Grade value is ["
<< result << "]"
<< endl;
Your 2nd if statement does nothing and the string result will print out "Not Processed".
Use a char to get your input that way you can use topper() from cctype lib to convert everything you get to uppercase then proceed from there. You can then compare the numerical values of what you received and print the appropriate result