// Author: Keith Shomper // Date: 9/22/03 // Purpose: To demonstrate the one-, two-, and multi-alternative selections // statements #include #include using namespace std; int main () { const int drivingAge = 16, votingAge = 18, adultAge = 21; int age; char Grade; float CS1210_Ave; string s; // Get the values of some variables to work with cout << "How old are you: "; cin >> age; cout << "What is your current average in CS1210: "; cin >> CS1210_Ave; getline(cin, s, '\n'); getline(cin, s, '\n'); // Single-alternative selection statement if (age == drivingAge) { cout << "Sweet 16!!!" << endl; } getline(cin, s, '\n'); // Two-alternative selection statement if (CS1210_Ave > 83) { cout << "Looks like your hard work is paying off."; } else { cout << "Let's work together to see if we can get that average up."; } cout << endl; getline(cin, s, '\n'); // Multi-alternative selection statement. What's wrong with this code?? if (CS1210_Ave >= 60) { Grade = 'D'; } else if (CS1210_Ave >= 70) { Grade = 'C'; } else if (CS1210_Ave >= 80) { Grade = 'B'; } else if (CS1210_Ave >= 90) { Grade = 'A'; } else { Grade = 'F'; } cout << "Your grade for the class up to now is a(an) " << Grade << endl; getline(cin, s, '\n'); // Corrected multi-alternative selection statement. if (CS1210_Ave >= 90) { Grade = 'A'; } else if (CS1210_Ave >= 80) { Grade = 'B'; } else if (CS1210_Ave >= 70) { Grade = 'C'; } else if (CS1210_Ave >= 60) { Grade = 'D'; } else { Grade = 'F'; } cout << "Your grade for the class up to now is a(an) " << Grade << endl; getline(cin, s, '\n'); // example switch statement (an alternative to the // multi-alternative selection when the cases can be listed or // enumerated). switch (Grade) { case 'D': cout << "time to get to work, because "; case 'C': cout << "we can do better"; break; case 'B': cout << "good job"; break; case 'A': cout << "great job"; break; default : cout << "you need to get a tutor, fast!"; } cout << endl; }