/* testmenu1.cpp 6/5/08 David Klick Demonstration of nested if/else using a menu example. */ #include using std::cin; using std::cout; void cont(); int main() { char choice; int numTickets = 0; double price = 0.0; double total = 0.0; bool error = false; bool done = false; cout << "Type of ticket\n\n" << " 1. (C)hild\n\n" << " 2. (A)dult\n\n" << " 3. (S)enior\n\n" << " 4. (Q)uit\n\n" << "Enter choice: "; cin >> choice; if (choice == '1' || choice == 'C' || choice == 'c') { price = 40.00; } else { if (choice == '2' || choice == 'A' || choice == 'a') { price = 20.00; } else { if (choice == '3' || choice == 'S' || choice == 's') { price = 45.00; } else { if (choice == '4' || choice == 'Q' || choice == 'q') { done = true; } else { error = true; cout << "Error: Invalid choice\n\n"; } } } } if (!error && !done) { cout << "\nHow many tickets? "; cin >> numTickets; total = price * numTickets; cout << "The total is $" << total << "\n\n"; } cont(); return 0; } void cont() { if (cin.rdbuf()->sungetc() != -1 && cin.get() != '\n') cin.ignore(80,'\n'); cout << "Press enter to continue..."; cin.get(); }