/* testsel4.cpp CIS 150 6/5/2008 David Klick Demonstration of switch structure. */ #include #include using std::cout; using std::cin; using std::fixed; using std::setprecision; using std::showpoint; void cont(); int main(void) { char choice = ' '; double price = 0.0; bool valid = true; // assume valid unless we get error bool quit = false; // user chose to quit program cout << "Ticket Seller 2000\n\n" << "1. (A)dult ticket ($12)\n\n" << "2. (S)enior ticket ($10)\n\n" << "3. (C)hild discount ($8)\n\n" << "4. (Q)uit\n\n" << "Choice: "; cin >> choice; switch (choice) { case '1': case 'A': case 'a': price = 12.00; break; case '2': case 'S': case 's': price = 10.00; break; case '3': case 'C': case 'c': price = 8.00; break; case '4': case 'Q': case 'q': quit = true; break; default: cout << "Error: Invalid choice\n\n"; valid = false; } if (!quit && valid) { cout << "The amount due is $" << fixed << showpoint << setprecision(2) << price << '\n'; } cout << "Thank you for using Ticket Guru XL7\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(); }