/* testsel3.cpp CIS 150 6/2/2005 David Klick Demonstration of if/else range checking. */ #include #include using std::cout; using std::cin; using std::fixed; using std::setprecision; using std::showpoint; int main(void) { double discPct; double price = 12.00; bool valid = true; // assume valid unless we get error cout << "Ticket Seller 2000\n\n" << "Tickets are $" << fixed << showpoint << setprecision(2) << price << " each.\n\n" << "Discount percentage (0 to 15): "; cin >> discPct; if (discPct < 0.0 || discPct > 15.0) { cout << "Error: invalid discount percentage\n"; valid = false; } else { price *= (1 - discPct/100.0); } if (valid) { cout << "The amount due is $" << price << '\n'; } return 0; }