#include using namespace std; int main() { // Write a program using switch that asks the user to // input a rating (integer 1-5) for a movie. // Based on the user's input, display a message // (e.g. "I didn't like that movie, either.") // Use the switch to capture user error, too. Loop // back around to read input again until the user // enters a valid rating. int rating; cout << "Please rate THE ADVENTURES OF MILO & OTIS\n"; cout << " on a 5-star scale (i.e. 1-5): "; cin >> rating; // one approach to input validation: // while ( rating < 1 || rating > 5 ) // { // cout << "Sorry, invalid. Try again: "; // cin >> rating; // } // is user input valid? initially, false bool is_valid = false; while ( is_valid == false ) { switch ( rating ) { case 1: is_valid = true; cout << "It wasn't that bad....\n"; break; case 2: is_valid = true; cout << "I thought it was better than 2 stars.\n"; break; case 3: is_valid = true; cout << "Mediocre? No way.\n"; break; case 4: is_valid = true; cout << "Only 4 stars?\n"; break; case 5: is_valid = true; cout << "Yes, I loved it, too!\n"; break; default: is_valid = false; cout << "Geez, can't you read directions?\n"; cout << "Please try again: "; cin >> rating; break; } } return 0; }