jaredec18

Untitled

Sep 9th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. #include<iostream>
  2.  
  3. using namespace std;
  4.  
  5. //Structure of the Menu Item
  6.  
  7. struct menuItem{
  8.  
  9. char description[25];
  10.  
  11. float price;
  12.  
  13. int count;
  14.  
  15. };
  16.  
  17. //For display float values upto 2 decimal
  18.  
  19. float round(float var)
  20.  
  21. {
  22.  
  23. float value = (int)(var * 100 + .5);
  24.  
  25. return (float)value / 100;
  26.  
  27. }
  28.  
  29. //For display Menu Item List
  30.  
  31. void displayMenu(menuItem menu[]){
  32.  
  33. int i;
  34.  
  35. for(i=0; i<6; i++)
  36.  
  37. cout << "\n["<< i+1 <<"] "<< menu[i].description <<"\t $" << round(menu[i].price) ;
  38.  
  39. }
  40.  
  41. //For Getting highest Menu Item List index
  42.  
  43. void mostorder(menuItem menu[]){
  44.  
  45. int i, countIndex = 0;
  46.  
  47. for(i=1; i < 6; i++){
  48.  
  49. if(menu[i].count > menu[countIndex].count)
  50.  
  51. countIndex = i;
  52.  
  53. }
  54.  
  55. cout << "\nItem ordered most often: " << menu[countIndex].description
  56.  
  57. <<" was purchased " << menu[countIndex].count << " times\n";
  58.  
  59. }
  60.  
  61. //For Order Menu's Item
  62.  
  63. float orderItems(menuItem menu[]){
  64.  
  65. int i = 0, j, order[10], flag = 0;
  66.  
  67. float subTotal = 0;
  68.  
  69. //Takes order list
  70.  
  71. cout<<"\nInput the item numbers for the order, 0 to quit\n";
  72.  
  73. do{
  74.  
  75. cin >> order[i++];
  76.  
  77. }while(order[i-1] != 0);
  78.  
  79. //checks whether extra item added
  80.  
  81. for(j=0; j < i-1; j++){
  82.  
  83. // cout << order[j] << "\t";
  84.  
  85. if(order[j] < 1 || order[j] > 6){
  86.  
  87. cout <<"\n*Error: There is no item."<< order[j];
  88.  
  89. flag = 1 ;
  90.  
  91. }
  92.  
  93. }
  94.  
  95. if(flag == 1){
  96.  
  97. cout<< "\nProcessing other items...";
  98.  
  99. }
  100.  
  101. //For calculating subtotal
  102.  
  103. for(j = 0; j < i-1; j++){
  104.  
  105. if(order[j] >= 1 || order[j] <= 6){
  106.  
  107. subTotal += menu[ (order[j]) - 1].price ;
  108.  
  109. menu[(order[j]) - 1].count++;
  110.  
  111. }
  112.  
  113. }
  114.  
  115. return subTotal;
  116.  
  117. }
  118.  
  119. int main(){
  120.  
  121. int i, j, order[10], countIndex;
  122.  
  123. float subTotal = 0, Tax = 0, Total, TotalSales;
  124.  
  125. char decision ;
  126.  
  127. menuItem menu[6] = { { "MacBook Air", 1099.00, 0 },
  128.  
  129. { "MacBook Pro", 1299.00, 0 },
  130.  
  131. { "iPad Air", 499.00, 0 },
  132.  
  133. { "IPad Pro 11-in", 799.00, 0 },
  134.  
  135. { "Pad Pro 12.9-in", 999.00, 0 },
  136.  
  137. { "Watch S4", 399.00, 0 }};
  138.  
  139. do{
  140.  
  141. displayMenu(menu);
  142.  
  143. subTotal = orderItems(menu);
  144.  
  145. Tax = subTotal * 0.0825;
  146.  
  147. cout << "\nSubtotal...$ " << round(subTotal);
  148.  
  149. cout << "\nTax........$ " << round(Tax);
  150.  
  151. Total = subTotal + Tax ;
  152.  
  153. cout << "\nTotal......$ " << round(Total);
  154.  
  155. cout << "\n\nPlease enter 'N' to take a new order and 'E' to exit: " ;
  156.  
  157. cin >> decision ;
  158.  
  159. TotalSales += Total;
  160.  
  161. }while(decision != 'E');
  162.  
  163. cout << "\n*** End of Day:";
  164.  
  165. cout << "\nTotal sales: $ " << round(TotalSales) ;
  166.  
  167. mostorder(menu);
  168.  
  169. return 1;
  170.  
  171. }
  172.  
  173. https://media.cheggcdn.com/media/2d1/2d150fb6-3bfd-4398-b775-b79fa53c6edc/phpV70m3N.png
  174.  
  175. https://media.cheggcdn.com/media/490/49026e75-d901-49c1-bfae-1371fec0eeb9/phpjjOBkn.png
  176.  
  177. https://media.cheggcdn.com/media/6fe/6fe106f7-f574-4475-b5e0-fbf157af81a6/phpi9oQnX.png
  178.  
  179. https://media.cheggcdn.com/media/83a/83ae0825-e174-4979-8b30-9a04fd46fc52/phpNBr8fX.png
  180.  
  181. https://media.cheggcdn.com/media/c9a/c9a843ce-c124-4b5b-9c4d-9f0bf05d6662/phpHQ0gny.png
Advertisement
Add Comment
Please, Sign In to add comment