Advertisement
Guest User

Untitled

a guest
Nov 4th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.80 KB | None | 0 0
  1. // CoffeeShop.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. using namespace std;
  7. #include <iomanip>
  8. #include <vector>
  9. #include <list>
  10. #include <string>
  11.  
  12. // Easy-to-edit Menu
  13. char Menu() {
  14.     int option;
  15.     cout << "\nWelcome to my coffee shop!" << endl;
  16.     cout << "\nPlease select an item you would like to order: " << endl;
  17.     cout << "1. Coffee" << endl;
  18.     cout << "2. Tea" << endl;
  19.     cout << "3. Soda" << endl;
  20.     cout << "4. Juice" << endl;
  21.     cout << "5. Special Item" << endl;
  22.     cout << "9. Exit" << endl;
  23.  
  24.     option = cin.get();
  25.  
  26.     if (option == '\n') {
  27.         option = 0;
  28.     }
  29.     return option;
  30. }
  31.  
  32. // Class for Special Items
  33. class SpecialItem
  34. {
  35.  
  36.     public:
  37.         SpecialItem(string s, double p, int n) {
  38.             title = s;
  39.             price = p;
  40.             amount = n;
  41.         }
  42.  
  43.         string title;
  44.         double price;
  45.         int amount;
  46.  
  47.         void setValues(string s, double p, int n) { title = s, price = p, amount = n; }
  48.  
  49.         string getName() { return title; }
  50.         double getPrice() { return price; }
  51.         int getAmount() { return amount; }
  52. };
  53.  
  54. int main()
  55. {
  56.     bool isOrdering = true;
  57.     // Declare all standard items with their prices
  58.     double coffee = 2.50, tea = 2.25, soda = 1.85, juice = 2.00;
  59.     // Declare amount of each item, initialize it to 0.
  60.     int amountCoffee = 0, amountTea = 0, amountSoda = 0, amountJuice = 0;
  61.  
  62.     list<SpecialItem> SpecialItems;
  63.  
  64.     char option = 1;
  65.     int input;
  66.     int quantity;
  67.     double orderTotal = 0;
  68.  
  69.     // Ordering Loop
  70.     do {
  71.         option = Menu();
  72.         switch (option) {
  73.         case '1':
  74.             if (amountCoffee == 0) {
  75.                 cout << "\nYou would like to order coffee, great!" << endl;
  76.                 cout << "Coffee costs $" << coffee << " each." << endl;
  77.                 cout << "\nPlease enter the quantity: ";
  78.                 cin >> quantity;
  79.             }
  80.             else {
  81.  
  82.                 cout << "You have already ordered coffee!" << endl;
  83.                 cout << "Would you like to change your order?" << endl;
  84.                 cout << "Input 1 if you would like to change the amount of coffee." << endl;
  85.                 cin >> input;
  86.                 if (input != 1) {
  87.                     break;
  88.                 }
  89.                 else {
  90.                     cout << "Coffee costs $" << setprecision(2) << coffee << " each." << endl;
  91.                     cout << "Please enter the new amount of coffee: ";
  92.                     cin >> quantity;
  93.                 }
  94.             }
  95.             amountCoffee = quantity;
  96.             cout << "\nYou have ordered " << amountCoffee << " coffees. " << endl;
  97.             break;
  98.         case '2':
  99.             if (amountTea == 0) {
  100.                 cout << "\nYou would like to order tea, great!" << endl;
  101.                 cout << "\nPlease enter the quantity: ";
  102.                 cin >> quantity;
  103.             }
  104.             else {
  105.                 cout << "You have already ordered tea!" << endl;
  106.                 cout << "Input 1 if you would like to change the amount of tea." << endl;
  107.                 cin >> input;
  108.                 if (input != 1) {
  109.                     break;
  110.                 }
  111.                 else {
  112.                     cout << "Please enter the new amount of tea: ";
  113.                     cin >> quantity;
  114.                 }
  115.             }
  116.             amountTea = quantity;
  117.             cout << "\nYou have ordered " << amountTea << " teas. " << endl;
  118.             break;
  119.         case '3':
  120.             if (amountSoda == 0) {
  121.                 cout << "\nYou would like to order soda, great!" << endl;
  122.                 cout << "\nPlease enter the quantity: ";
  123.                 cin >> quantity;
  124.             }
  125.             else {
  126.                 cout << "You have already ordered soda!" << endl;
  127.                 cout << "Input 1 if you would like to change the amount of soda." << endl;
  128.                 cin >> input;
  129.                 if (input != 1) {
  130.                     break;
  131.                 }
  132.                 else {
  133.                     cout << "Please enter the new amount of soda: ";
  134.                     cin >> quantity;
  135.                 }
  136.             }
  137.             amountSoda = quantity;
  138.             cout << "\nYou have ordered" << amountSoda << " sodas. " << endl;
  139.             break;
  140.         case '4':
  141.             if (amountJuice == 0) {
  142.                 cout << "\nYou would like to order juice, great!" << endl;
  143.                 cout << "\nPlease enter the quantity: ";
  144.                 cin >> quantity;
  145.             }
  146.             else {
  147.                 cout << "You have alreadered ordered juice!" << endl;
  148.                 cout << "Input 1 if you would like to change the amount of soda." << endl;
  149.                 cin >> input;
  150.                 if (input != 1) {
  151.                     break;
  152.                 }
  153.                 else {
  154.                     cout << "Please enter the new amount of juice: ";
  155.                     cin >> quantity;
  156.                 }
  157.             }
  158.             cout << "\nYou have ordered " << amountJuice << " juices. " << endl;
  159.             amountJuice = quantity;
  160.             break;
  161.         case '5':
  162.         {
  163.             string name;
  164.             double price;
  165.             int quantity;
  166.             cout << "\nYou've chosen to order a special item, yay!" << endl;
  167.             cout << "\nPlease enter the name of the item: ";
  168.             cin.ignore();
  169.             getline(cin, name);
  170.             cout << "\nPlease enter the price of the item: ";
  171.             cin >> price;
  172.             cout << "\nFinally, enter the quantity of the item: ";
  173.             cin >> quantity;
  174.  
  175.             SpecialItem item(name, quantity, price);
  176.  
  177.             SpecialItems.push_front(item);
  178.  
  179.             cout << "\nThank you for ordering a special item!" << endl;
  180.             cout << "You ordered " << quantity << " " << name << "s at $" << price << " each." << endl;
  181.             break;
  182.         }
  183.         case '0':
  184.         {
  185.             cout << "Thank you for your order!" << endl;
  186.             cout << "\nYou ordered: " << endl;
  187.             if (amountCoffee != 0) {
  188.                 cout << amountCoffee << " coffees" << endl;
  189.             }
  190.             if (amountTea != 0) {
  191.                 cout << amountTea << " teas" << endl;
  192.             }
  193.             if (amountSoda != 0) {
  194.                 cout << amountSoda << " sodas" << endl;
  195.             }
  196.             if (amountJuice != 0) {
  197.                 cout << amountJuice << " juices" << endl;
  198.             }
  199.  
  200.             list<SpecialItem>::iterator it;
  201.             for (it = SpecialItems.begin(); it != SpecialItems.end(); it++) {
  202.                 string name = it->title;
  203.                 double price = it->price;
  204.                 int quantity = it->amount;
  205.  
  206.                 cout << quantity << " " << name << "s, at $" << price << " each." << endl;
  207.                 orderTotal += price * quantity;
  208.             }
  209.  
  210.             orderTotal += (coffee * amountCoffee) + (tea * amountTea) + (soda * amountSoda) + (juice * amountJuice);
  211.  
  212.  
  213.             cout << "Your orders comes to a total of $" << setprecision(2) << orderTotal << endl;
  214.             cout << "Thank you, and enjoy your items!";
  215.             break;
  216.         }
  217.         case '9':
  218.                 isOrdering = false;
  219.                 break;
  220.         }
  221.     } while (isOrdering = true);
  222.  
  223.     return 0;
  224. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement