/* asst02.cpp CIS 150 06/09/05 David Klick Solution to programming assignment #2 */ #include #include using std::cout; using std::cin; using std::fixed; using std::setw; using std::showpoint; using std::setprecision; using std::endl; const double TAXRATE = .075; int main(void) { char choice; int qty = 0; double disc = 0.0; double discAmt = 0.0; double subtotal = 0.0; double tax = 0.0; double total = 0.0; bool valid = true; // assume user entry will be valid bool done = false; // assume not done double pricePer = 0.0; // display menu cout << "Choose item for purchase:\n\n" " 1. (P)rinter - Laserjet 2550n ($699)\n\n" " 2. (L)aptop computer - Winbook C540 ($1099.95)\n\n" " 3. (D)esktop computer - Powerspec 1550 ($395.50)\n\n" " 4. (Q)uit\n\n" "Please enter choice: "; cin >> choice; // process manu selection switch (choice) { case '1': case 'P': case 'p': pricePer = 699.00; break; case '2': case 'L': case 'l': pricePer = 1099.95; break; case '3': case 'D': case 'd': pricePer = 395.50; break; case '4': case 'Q': case 'q': done = true; break; default: cout << choice << " is not a valid choice\n"; valid = false; } // get quantity and validate it (only if not done and no error so far) if (valid && !done) { cout << "\nEnter quantity desired (0-999): "; cin >> qty; if (qty<0 || qty>999) { cout << qty << " is not a valid quantity\n"; valid = false; } else { if (qty < 12) disc = 0.0; else if (qty < 100) disc = 0.10; else disc = 0.20; } } // calculate and display output (only if not done and no error so far) if (valid && !done) { subtotal = pricePer * qty; discAmt = subtotal * disc; tax = TAXRATE * (subtotal-discAmt); total = subtotal - discAmt + tax; cout << fixed << showpoint << setprecision(2) << "\n\n" << " Price: " << setw(10) << pricePer << "\n" << "Quantity: " << setw(7) << qty << "\n" << "Subtotal: " << setw(10) << subtotal << "\n" << "Discount: " << setw(10) << discAmt << "\n" << " Tax: " << setw(10) << tax << "\n" << " Total: " << setw(10) << total << endl; } return 0; }