/*****************************************************************/ /* Author: Chang */ /* Aim for: CS135 class */ /* Problem: A program demonstrating if-else and switch statements*/ /*****************************************************************/ //preprocessor directives #include using namespace std; //function phototypes void printIntMenu (); void printCharMenu (); int main () { int intChoice; char charChoice; printIntMenu (); cin >> intChoice; // if-else structure to process integer menu choice if (intChoice == 1) cout << "You chose: Cheesecake." << endl; else if (intChoice == 2 || intChoice == 6) cout << "You chose: Chocolate Pie." << endl; else if (intChoice >= 3 && intChoice <= 5) cout << "You chose: Icecream." << endl; //A curly braces is REQUIRED for multiple statements. else { cout << "OOPS... no matching" << endl; cout << "Welcome to come again." << endl << endl; } printCharMenu (); cin >> charChoice; // switch structure to process character menu choice switch (charChoice) { case 'a': case '1': cout << "You chose: Harry Potter and the Goblet of Fire" << endl; break; case 'b': case '2': cout << "You chose: Shrek 2" << endl; break; case 'c': case '3': cout << "You chose: Spiderman 2" << endl; break; case 'd': case '4': cout << "The Incredibles? Did you really watch it?" << endl; break; default: cout << "OOPS ... no matching movies" << endl; } system("PAUSE"); return 0; } /** * Prints an integer menu list. */ void printIntMenu () { cout << "Please choose your favorite food by typing in the number:\n"; cout << "1. Cheesecake" << endl << "2 or 6. Chocolate Pie" << endl << "3 or 4 or 5. Icecream" << endl; } /** * Prints an character menu list. */ void printCharMenu () { cout << "Please choose your best movie from the following menu:" << endl; cout << "a or 1. Harry Potter and the Goblet of Fire" << endl; cout << "b or 2. Shrek 2" << endl; cout << "c or 3. Spiderman 2" << endl; cout << "d or 4. The Incredibles" << endl; }