Advertisement
riggnaros

9_5 mindtap

Nov 28th, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.67 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <fstream>
  5. #include <string>
  6.  
  7. using namespace std;
  8.  
  9. struct menuItemType {
  10.     string menuItem;
  11.     double menuPrice;
  12.     char selected;
  13.     int quantity;
  14. };
  15.  
  16. void getData(menuItemType menuList[]); //This function loads the data into the array menuList
  17. void showMenu(menuItemType menuList[]); //This function shows the different items offered by the restaurant and tells the user how to select the items.
  18. void printCheck(menuItemType menuList[]); //5% sales tax - Format your output with two decimal places. The name of each item in the output must be left justified.
  19.  
  20. int main()
  21. {
  22.  
  23.     menuItemType menuList[8];
  24.     getData(menuList);
  25.     showMenu(menuList);
  26.  
  27.     return 0;
  28. }
  29.  
  30. void getData(menuItemType menuList[])
  31. {
  32.  
  33.     ifstream infile;
  34.     infile.open("9_4datafile.txt");
  35.  
  36.     for (int i = 0; i < 8; i++) {
  37.         getline(infile, menuList[i].menuItem);
  38.         infile >> menuList[i].menuPrice;
  39.         menuList[i].selected = 'n';
  40.         menuList[i].quantity = 0;
  41.         infile.ignore();
  42.     }
  43.     infile.close();
  44. };
  45.  
  46. void showMenu(menuItemType menuList[])
  47. {
  48.  
  49.     int count = 1;
  50.     int itemNumber = 0;
  51.     char selection;
  52.  
  53.     cout << "\n Welcome to Charlie Tuna's Resturant"
  54.          << "\n----Today's Menu----"
  55.          << endl;
  56.  
  57.     for (int i = 0; i < 8; i++) {
  58.         cout << count++ << ". ";
  59.         cout << menuList[i].menuItem << " "
  60.              << fixed << setprecision(2) << "$" << menuList[i].menuPrice
  61.              << endl;
  62.     }
  63.  
  64.     cout << "\nYou can make up to 8 different selections."
  65.          << "\nDo you want to make selection Y/y (Yes), N/n (No): ";
  66.     cin >> selection;
  67.  
  68.     while (selection == 'y' || selection == 'Y') {
  69.  
  70.         cout << "\nEnter item number: ";
  71.         cin >> itemNumber;
  72.         menuList[itemNumber - 1].selected = 'y';
  73.         cout << "\nHow many would you like to order?: ";
  74.         cin >> menuList[itemNumber - 1].quantity;
  75.         cout << "\nWould you like to make another selection: ";
  76.         cin >> selection;
  77.     }
  78.     printCheck(menuList);
  79.     cout << "\nThank you and have a nice day!";
  80. };
  81.  
  82. void printCheck(menuItemType menuList[])
  83. {
  84.  
  85.     double grandTotal = 0;
  86.     double rollingTotal = 0;
  87.  
  88.     for (int i = 0; i < 8; i++) {
  89.  
  90.         if (menuList[i].selected == 'y' || menuList[i].selected == 'Y') {
  91.             rollingTotal += (menuList[i].menuPrice) * (menuList[i].quantity);
  92.             grandTotal = rollingTotal + (rollingTotal * 0.05);
  93.             cout << menuList[i].quantity << " " << menuList[i].menuItem << endl;
  94.         }
  95.     }
  96.  
  97.     cout << "\nYour total is: $" << fixed << setprecision(2) << grandTotal << endl;
  98. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement