int main()
{
// scores required for each letter grade.
const int A_SCORE = 90,
B_SCORE = 80,
C_SCORE = 70,
D_SCORE = 60,
F_SCORE = 0;
int numericGrade; // Holds a numeric test score
char letterGrade; // Holds a letter grade
int gradePoints; // Holds number of points earned
// Get the numeric score
cout << "Please type in your grade: \n";
cin >> numericGrade;
// Determine the letter grade. What grade will be assigned?
if (numericGrade >= A_SCORE)
{
letterGrade = 'A';
gradePoints = 4;
}
else if (numericGrade >= B_SCORE)
{
letterGrade = 'B';
gradePoints = 3;
}
else if (numericGrade >= C_SCORE)
{
letterGrade = 'C';
gradePoints = 2;
}
else if (numericGrade >= D_SCORE)
{
letterGrade = 'D';
gradePoints = 1;
}
else if (numericGrade >= F_SCORE)
{
letterGrade = 'F';
gradePoints = 0;
}
// Display the letter grade and points earned
cout << "\tYou made a " << letterGrade << " in the class and earned " << gradePoints << " points.\n";
system("pause");
return 0;
}
Noticeably omitting the one thing the OP asked for: a switch statement. (Also, redundant conditions -- avg must be less than 90 if line 36 is evaluated so there's no reason to check for it.)
To the OP: Switches don't work for ranges unless you can map the ranges to specific integral values. Something like the following for your use case:
#include <iostream>
usingnamespace std;
int main()
{
// scores required for each letter grade.
constint A_SCORE = 90,
B_SCORE = 80,
C_SCORE = 70,
D_SCORE = 60,
F_SCORE = 0;
int numericGrade; // Holds a numeric test score
char letterGrade; // Holds a letter grade
int gradePoints; // Holds number of points earned
cout << "Please type in your grade: \n";
cin >> numericGrade;
switch (numericGrade / 10) {
case 10: // fall through to 9.
case 9: letterGrade = 'A'; gradePoints = 4; break;
case 8: letterGrade = 'B'; gradePoints = 3; break;
case 7: letterGrade = 'C'; gradePoints = 2; break;
case 6: letterGrade = 'D'; gradePoints = 1; break;
default: letterGrade = 'F'; gradePoints = 0; break;
}
// Display the letter grade and points earned
cout << "\tYou made a " << letterGrade << " in the class and earned " << gradePoints << " points.\n";
}