riggnaros

coffee_calc

Oct 25th, 2017
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.81 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <limits>
  4. #include <cmath>
  5. #include <iomanip>
  6.  
  7. using namespace std;
  8.  
  9. void showMenu(); //a function to show the user how to use the program
  10.  
  11. void sellCoffee(int quantity, char size, double totalPrice, double smallPrice, double medPrice, double largePrice, int& totalCupsSmall, int& totalCupsMed, int& totalCupsLargem, double& grandTotal); //a function to sell coffee  -- Buy coffee in any size and in any number of cups.
  12.  
  13. void showCoffeeStats(int& totalCupsSmall, int& totalCupsMed, int& totalCupsLarge); //a function to show the number of cups of each size sold -- avaliable at any time.
  14.  
  15. void showTotalCoffee(int& totalCupsSmall, int& totalCupsMed, int& totalCupsLarge, int& allSizeTotal); //a function to show the total amount of coffee sold  -- avaliable at any time.
  16.  
  17. void showTotalMoney(double& grandTotal); //and a function to show the total money made.  -- avaliable at any time.
  18.  
  19. void exitProgram();
  20.  
  21. int main()
  22.  
  23. {
  24.  
  25.     int selection = 0;
  26.     char size;
  27.     int quantity = 0;
  28.     double totalPrice = 0;
  29.  
  30.     //int smallOz=9;
  31.     //int medOz=12;
  32.     //int largeOz=15;
  33.  
  34.     double smallPrice = 1.75;
  35.     double medPrice = 1.90;
  36.     double largePrice = 2.00;
  37.  
  38.     int totalCupsSmall = 0;
  39.     int totalCupsMed = 0;
  40.     int totalCupsLarge = 0;
  41.  
  42.     double grandTotal = 0;
  43.     int allSizeTotal =0;
  44.    
  45.     showMenu();
  46.  
  47.     while (true) {
  48.         cout<<endl;
  49.    
  50.     cout << "\nPlease enter your selection: ";
  51.     cin >> selection;
  52.  
  53.     if (selection == 1) {
  54.         sellCoffee(quantity, size, totalPrice, smallPrice, medPrice, largePrice, totalCupsSmall, totalCupsMed, totalCupsLarge, grandTotal);
  55.     }
  56.     else if (selection == 2) {
  57.         showCoffeeStats(totalCupsSmall, totalCupsMed, totalCupsLarge);
  58.     }
  59.     else if (selection == 3) {
  60.         showTotalCoffee(totalCupsSmall, totalCupsMed, totalCupsLarge, allSizeTotal);
  61.     }
  62.     else if (selection == 4) {
  63.         showTotalMoney(grandTotal);
  64.     }
  65.     else if (selection == 5) {
  66.         exitProgram();
  67.         }
  68.     }
  69.  
  70.     return 0;
  71. }
  72.  
  73. void showMenu()
  74. {
  75.  
  76.     cout << "************Welcome to the Coffee Shop!************";
  77.     cout << "\n               ****MENU****                      ";
  78.     cout << "\n   Small Coffee  - $1.75                         ";
  79.     cout << "\n   Medium Coffee - $1.90                         ";
  80.     cout << "\n   Large Coffee  - $2.00                         ";
  81.     cout << "\n   Press '1' to order your own coffee!           ";
  82.     cout << "\n   Press '2' to see the total cups sold!         ";
  83.     cout << "\n   Press '3' to see the total coffee sold!       ";
  84.     cout << "\n   Press '4' to see the total money earned!      ";
  85.     cout << "\n   Press '5' to exit the program!                ";
  86.     cout << "\n*************************************************";
  87.     cout << endl;
  88. };
  89.  
  90. void sellCoffee(int quantity, char size, double totalPrice, double smallPrice, double medPrice, double largePrice, int& totalCupsSmall, int& totalCupsMed, int& totalCupsLarge, double& grandTotal)
  91. {
  92.  
  93.     cout << "\nWhat size coffee would you like to purchase?(S=Small / M=Med / L=Large): ";
  94.     cin >> size;
  95.     cout << "\nHow many coffee would you like to order?: " << quantity;
  96.     cin >> quantity;
  97.     cout << "\nWould you like to order another size of coffee?: ";
  98.  
  99.     if (size == 'S' || size == 's') {
  100.         totalPrice = (quantity * smallPrice);
  101.         totalCupsSmall += quantity;
  102.     }
  103.     else if (size == 'M' || size == 'm') {
  104.         totalPrice = (quantity * medPrice);
  105.         totalCupsMed += quantity;
  106.     }
  107.     else if (size == 'L' || size == 'l') {
  108.         totalPrice = (quantity * largePrice);
  109.         totalCupsLarge += quantity;
  110.     }
  111.  
  112.     grandTotal += totalPrice;
  113.  
  114.     cout << "\nAwesome, thank you! These are your order details!: ";
  115.     cout << fixed << showpoint << setprecision(2);
  116.     cout << "\n Number of cups ordered: " << quantity;
  117.     cout << "\n Size of coffee ordered: " << size;
  118.     cout << "\n Total Price of order: $" << totalPrice;
  119.    
  120.    
  121. };
  122.  
  123. void showCoffeeStats(int& totalCupsSmall, int& totalCupsMed, int& totalCupsLarge)
  124. {
  125.  
  126.     cout << "\nHere are the total stats for each size of coffee sold: ";
  127.     cout << "\nLarge Coffee: " <<totalCupsLarge;
  128.     cout << "\nMedium Coffee: " <<totalCupsMed;
  129.     cout << "\nSmall Coffee: " <<totalCupsSmall;
  130.    
  131.    
  132. };
  133.  
  134. void showTotalMoney(double& grandTotal)
  135. {
  136.  
  137.     cout << fixed << showpoint << setprecision(2);
  138.     cout << "\nTotal Money Earned: $" << grandTotal;
  139.  
  140. };
  141.  
  142. void showTotalCoffee(int& totalCupsSmall, int& totalCupsMed, int& totalCupsLarge, int& allSizeTotal)
  143. {
  144.  
  145.     allSizeTotal = (totalCupsLarge + totalCupsMed + totalCupsSmall);
  146.     cout << "\nHere is the total number of coffee cups sold (all sizes): " << allSizeTotal;
  147. };
  148.  
  149. void exitProgram()
  150. {
  151.     exit(0);
  152. };
Advertisement
Add Comment
Please, Sign In to add comment