Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // CoffeeShop.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream>
- using namespace std;
- #include <iomanip>
- #include <vector>
- #include <list>
- #include <string>
- // Easy-to-edit Menu
- char Menu() {
- int option;
- cout << "\nWelcome to my coffee shop!" << endl;
- cout << "\nPlease select an item you would like to order: " << endl;
- cout << "1. Coffee" << endl;
- cout << "2. Tea" << endl;
- cout << "3. Soda" << endl;
- cout << "4. Juice" << endl;
- cout << "5. Special Item" << endl;
- cout << "9. Exit" << endl;
- option = cin.get();
- if (option == '\n') {
- option = 0;
- }
- return option;
- }
- // Class for Special Items
- class SpecialItem
- {
- public:
- SpecialItem(string s, double p, int n) {
- title = s;
- price = p;
- amount = n;
- }
- string title;
- double price;
- int amount;
- void setValues(string s, double p, int n) { title = s, price = p, amount = n; }
- string getName() { return title; }
- double getPrice() { return price; }
- int getAmount() { return amount; }
- };
- int main()
- {
- bool isOrdering = true;
- // Declare all standard items with their prices
- double coffee = 2.50, tea = 2.25, soda = 1.85, juice = 2.00;
- // Declare amount of each item, initialize it to 0.
- int amountCoffee = 0, amountTea = 0, amountSoda = 0, amountJuice = 0;
- list<SpecialItem> SpecialItems;
- char option = 1;
- int input;
- int quantity;
- double orderTotal = 0;
- // Ordering Loop
- do {
- option = Menu();
- switch (option) {
- case '1':
- if (amountCoffee == 0) {
- cout << "\nYou would like to order coffee, great!" << endl;
- cout << "Coffee costs $" << coffee << " each." << endl;
- cout << "\nPlease enter the quantity: ";
- cin >> quantity;
- }
- else {
- cout << "You have already ordered coffee!" << endl;
- cout << "Would you like to change your order?" << endl;
- cout << "Input 1 if you would like to change the amount of coffee." << endl;
- cin >> input;
- if (input != 1) {
- break;
- }
- else {
- cout << "Coffee costs $" << setprecision(2) << coffee << " each." << endl;
- cout << "Please enter the new amount of coffee: ";
- cin >> quantity;
- }
- }
- amountCoffee = quantity;
- cout << "\nYou have ordered " << amountCoffee << " coffees. " << endl;
- break;
- case '2':
- if (amountTea == 0) {
- cout << "\nYou would like to order tea, great!" << endl;
- cout << "\nPlease enter the quantity: ";
- cin >> quantity;
- }
- else {
- cout << "You have already ordered tea!" << endl;
- cout << "Input 1 if you would like to change the amount of tea." << endl;
- cin >> input;
- if (input != 1) {
- break;
- }
- else {
- cout << "Please enter the new amount of tea: ";
- cin >> quantity;
- }
- }
- amountTea = quantity;
- cout << "\nYou have ordered " << amountTea << " teas. " << endl;
- break;
- case '3':
- if (amountSoda == 0) {
- cout << "\nYou would like to order soda, great!" << endl;
- cout << "\nPlease enter the quantity: ";
- cin >> quantity;
- }
- else {
- cout << "You have already ordered soda!" << endl;
- cout << "Input 1 if you would like to change the amount of soda." << endl;
- cin >> input;
- if (input != 1) {
- break;
- }
- else {
- cout << "Please enter the new amount of soda: ";
- cin >> quantity;
- }
- }
- amountSoda = quantity;
- cout << "\nYou have ordered" << amountSoda << " sodas. " << endl;
- break;
- case '4':
- if (amountJuice == 0) {
- cout << "\nYou would like to order juice, great!" << endl;
- cout << "\nPlease enter the quantity: ";
- cin >> quantity;
- }
- else {
- cout << "You have alreadered ordered juice!" << endl;
- cout << "Input 1 if you would like to change the amount of soda." << endl;
- cin >> input;
- if (input != 1) {
- break;
- }
- else {
- cout << "Please enter the new amount of juice: ";
- cin >> quantity;
- }
- }
- cout << "\nYou have ordered " << amountJuice << " juices. " << endl;
- amountJuice = quantity;
- break;
- case '5':
- {
- string name;
- double price;
- int quantity;
- cout << "\nYou've chosen to order a special item, yay!" << endl;
- cout << "\nPlease enter the name of the item: ";
- cin.ignore();
- getline(cin, name);
- cout << "\nPlease enter the price of the item: ";
- cin >> price;
- cout << "\nFinally, enter the quantity of the item: ";
- cin >> quantity;
- SpecialItem item(name, quantity, price);
- SpecialItems.push_front(item);
- cout << "\nThank you for ordering a special item!" << endl;
- cout << "You ordered " << quantity << " " << name << "s at $" << price << " each." << endl;
- break;
- }
- case '0':
- {
- cout << "Thank you for your order!" << endl;
- cout << "\nYou ordered: " << endl;
- if (amountCoffee != 0) {
- cout << amountCoffee << " coffees" << endl;
- }
- if (amountTea != 0) {
- cout << amountTea << " teas" << endl;
- }
- if (amountSoda != 0) {
- cout << amountSoda << " sodas" << endl;
- }
- if (amountJuice != 0) {
- cout << amountJuice << " juices" << endl;
- }
- list<SpecialItem>::iterator it;
- for (it = SpecialItems.begin(); it != SpecialItems.end(); it++) {
- string name = it->title;
- double price = it->price;
- int quantity = it->amount;
- cout << quantity << " " << name << "s, at $" << price << " each." << endl;
- orderTotal += price * quantity;
- }
- orderTotal += (coffee * amountCoffee) + (tea * amountTea) + (soda * amountSoda) + (juice * amountJuice);
- cout << "Your orders comes to a total of $" << setprecision(2) << orderTotal << endl;
- cout << "Thank you, and enjoy your items!";
- break;
- }
- case '9':
- isOrdering = false;
- break;
- }
- } while (isOrdering = true);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement