/* testsel4.cpp CIS 150 6/2/2005 David Klick Demonstration of switch structure. */ #include #include using std::cout; using std::cin; using std::fixed; using std::setprecision; using std::showpoint; int main(void) { char choice; double price; 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"; return 0; }