Advertisement
Guest User

jp switch

a guest
Sep 18th, 2014
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.58 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     // Softdrinks
  8.     int pepsi = 20;
  9.     int coke = 25;
  10.  
  11.     // Bread
  12.     int sandwich = 25;
  13.     int bun = 20;
  14.  
  15.     // Snacks
  16.     int oishi = 15;
  17.     int pewee = 18;
  18.  
  19.     // User choices
  20.     char category;
  21.     string choice;
  22.  
  23.     // Money calculations variables
  24.     int totalAmount;
  25.     int payment;
  26.     int change;
  27.  
  28.     cout << "Our menu:" << endl;
  29.     cout << "A. Softdrinks (Pepsi = 20 ; Coke = 25)" << endl;
  30.     cout << "B. Bread (Sandwich = 25 ; Bun = 20)" << endl;
  31.     cout << "C. Snacks (Oishi = 15 ; Peewee = 18)" << endl;
  32.  
  33.     cout << "Choose category: ";
  34.     cin >> category;
  35.     cout << "Choose item: ";
  36.     switch(category) {
  37.         case 'A':
  38.         case 'a':
  39.             cin >> choice;
  40.  
  41.             if (choice == "Pepsi" || choice == "pepsi") {
  42.                 totalAmount = pepsi;
  43.             } else if (choice == "Coke" || choice == "coke") {
  44.                 totalAmount = pepsi;
  45.             }
  46.             break;
  47.         case 'B':
  48.         case 'b':
  49.             cin >> choice;
  50.  
  51.             if (choice == "Sandwich" || choice == "sandwich") {
  52.                 totalAmount = sandwich;
  53.             } else if (choice == "Bun" || choice == "bun") {
  54.                 totalAmount = bun;
  55.             }
  56.             break;
  57.         case 'C':
  58.         case 'c':
  59.             cin >> choice;
  60.  
  61.             if (choice == "Oishi" || choice == "oishi") {
  62.                 totalAmount = oishi;
  63.             } else if (choice == "Peewee" || choice == "pewee") {
  64.                 totalAmount = pewee;
  65.             }
  66.     }
  67.  
  68.     cout << "Total amout is: " << totalAmount << endl;
  69.     cout << "Your payment: ";
  70.     cin >> payment;
  71.  
  72.     if (payment < totalAmount) {
  73.         cout << "Payment insufficient" << endl;
  74.     } else {
  75.         change = payment - totalAmount;
  76.         cout << "Here's your change: " << change << endl;
  77.     }
  78.  
  79.     return 0;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement