/* testsel1.cpp CIS 150 6/5/2008 David Klick Demonstration of if statement. */ #include #include using std::cout; using std::cin; using std::fixed; using std::setprecision; using std::showpoint; void cont(); int main(void) { const double DISC_PCT = .15; char choice = ' '; double price = 12.00; cout << "Ticket Seller 2000\n\n" << "Tickets are $" << fixed << showpoint << setprecision(2) << price << " each.\n\n" << "Apply senior discount? (Y/N) "; cin >> choice; if (choice == 'Y' || choice == 'y') { price *= (1 - DISC_PCT); } cout << "The amount due is $" << fixed << showpoint << setprecision(2) << price << '\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(); } /* Sample run #1: Ticket Seller 2000 Tickets are $12.00 each. Apply senior discount? (Y/N) N The amount due is $12.00 Press enter to continue... Sample run #2: Ticket Seller 2000 Tickets are $12.00 each. Apply senior discount? (Y/N) Y The amount due is $10.20 Press enter to continue... */