This is the assignment I'm working on:
Write a program that prompts the user to enter the points earned for a course and determines the grade. The program should display the grade and the message string for the grade. Use 'if else' statements to determine the grade and the switch statement to print the message string.
I wrote the code and it executes without any debugging errors. The problem is, no matter what I input as my PointsEarned
, I only get the output for F! For example, if I input "90":
Try Harder Next Time.
GRADE: F
What's the problem? Am I putting my switch statement in the wrong place? Here's the code:
#include <iostream>
using namespace std;
int main()
{
int PointsEarned;
char Grade;
cout << "Please input the points earned in the course: ";
cin >> PointsEarned;
if (0 <= PointsEarned < 60) {
Grade = 'F';
}
else if (60 <= PointsEarned < 70) {
Grade = 'D';
}
else if (70 <= PointsEarned < 80) {
Grade = 'C';
}
else if (80 <= PointsEarned < 90) {
Grade = 'B';
}
else if (90 <= PointsEarned) {
Grade = 'A';
}
else{
cout << "That is not a valid input.";
}
switch (Grade)
{
case 'F':
case 'D':
cout << "Try Harder Next Time." << endl;
break;
case 'C':
cout << "Good." << endl;
break;
case 'B':
cout << "Very good." << endl;
break;
case 'A':
cout << "Excellent." << endl;
break;
default:
cout << "Please choose a valid input to receive your grade." << endl;
}
cout << "GRADE: " << Grade << endl;
}