garryhtreez

5.17

Nov 14th, 2020 (edited)
1,110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.47 KB | None | 0 0
  1. /* 5.17 Calculating Sales
  2.         Deitel & Deitel C++ How to Program, 10th ed (Indian subcontinent adaptation)
  3.     Visual Studio Community 2019 */
  4.  
  5. #include<iostream>
  6. using namespace std;
  7.  
  8. int main() {
  9.     int itemNum{ 0 }, quant;
  10.     double total{ 0.0 };
  11.     while (true) {
  12.         cout << "Please enter item # (1-5). Enter 6 to end.\n";
  13.         cin >> itemNum;
  14.         if (itemNum < 1 || itemNum > 6) {
  15.             cout << "Invalid item.\n\n";
  16.             continue;
  17.         }
  18.         if (itemNum == 6) {
  19.             cout << "\nDone purchasing. Calculating order...\n\n";
  20.             break;
  21.         }
  22.         cout << "Please enter the quantity of item " << itemNum << " you wish to buy\n";
  23.         cin >> quant;
  24.         switch (itemNum) {
  25.         case 1:
  26.             cout << "These are $2.98 each\n";
  27.             total += quant * 2.98;
  28.             cout << "Your running total is now: " << "$"<< total << "\n\n";
  29.             break;
  30.         case 2:
  31.             cout << "These are $4.50 each\n";
  32.             total += quant * 4.50;
  33.             cout << "Your running total is now: " << "$"<< total << "\n\n";
  34.             break;
  35.         case 3:
  36.             cout << "These are $9.98 each\n";
  37.             total += quant * 9.98;
  38.             cout << "Your running total is now: " << "$"<< total << "\n\n";
  39.             break;
  40.         case 4:
  41.             cout << "These are $4.49 each\n";
  42.             total += quant * 4.49;
  43.             cout << "Your running total is now: " << "$" << total << "\n\n";
  44.             break;
  45.         case 5:
  46.             cout << "These are $6.87 each\n";
  47.             total += quant * 6.87;
  48.             cout << "Your running total is now: " << "$" << total << "\n";
  49.             break;
  50.         }
  51.     }
  52.     cout << "Total cost: " << total << "\n\n";
  53.  
  54.     return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment