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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
#include <iostream>
using namespace std;
int main()
{
char course = '0'; // <--
double Average{0}, Homework{0}, Midterm1{0}, Midterm2{0}, Final{0}; // <--
cout << "What course do you want? ";
cin >> course;
cout << "Homework: ";
cin >> Homework;
cout << "Midterm 1: ";
cin >> Midterm1;
cout << "Midterm 2: ";
cin >> Midterm2;
cout << "Final: ";
cin >> Final;
cout << endl;
if(course == 'A') // <--
Average = Homework*0.1 + Midterm1*.25 + Midterm2*.25 + Final*.4;
if(course == 'B') // <--
Average = Homework*0.15 + Midterm1*.25 + Midterm2*.25 + Final*.35;
struct GradeData {
double ceiling;
const char *grade;
const char *comment;
};
GradeData data[] = {
{ 60, "F", "You failed." },
{ 70, "D", "You passed." },
{ 80, "C", "You passed." },
{ 90, "B", "Good work!" },
{ 100, "A", "Congratulations" },
{ 0, nullptr, nullptr } // marks end of array
};
if ((Average < 0) || (Average >= 100))
{
cout << "Invalid entry." << endl << "Please try again" << endl;
} else {
// If you get here then the grade must be within the table
for (int i=0; data[i].grade != nullptr; ++i) {
if (Average < data[i].ceiling) {
cout << "Your Average is " << Average << endl
<< "Your grade is " << data[i].grade << ".\n"
<< data[i].comment << endl;
break;
}
}
}
return 0;
}
|