Advertisement
SmellyBadger

Untitled

Oct 18th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.24 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. #include <iomanip>
  4.  
  5.  
  6.  
  7. using namespace std;
  8.  
  9. const float PAPER_COPY = 2;
  10. const float HARD_COPY = 5;
  11. const float TAX_RATE = 0.06;
  12. const float DISCOUNT_RATE = 0.10;
  13. int main()
  14.  
  15. {
  16.  
  17. cout << fixed << showpoint << setprecision(2);
  18. float bookCost; // Represents the cost of a book
  19. char action; //
  20. int checkedOut; // Variable for number of books checked out
  21. int customerNumber; // to keep track of total number of customers
  22. bool customerFinished; // Boolean for satisfying whether or not the customer is finished purchasing
  23. float totalSale; // Variable for total cost of the purchase (not including tax and discount)
  24. float totalDiscount; // Total discount for a purchase
  25. float discountAmount; // Discount for a single book
  26. customerFinished = false;
  27. float totalcustomerSalesWithoutTax; // total customer sales without tax
  28. float MaxcustomerSale; // Maximum Sale of all customers
  29. float totalCustomerDiscounts; // The combined discount of all customers
  30. //float taxAmount; // amount of tax
  31. float customerCost; // tax + sales
  32. cout << "Welcome to Book Store." << endl;
  33.  
  34. cout << "Enter \"c\" to checkout a new customer, or \"q\" to close batch and print a daily report." << endl;
  35. cin >> action;
  36.  
  37.  
  38. customerNumber = 0;
  39. MaxcustomerSale = 0;
  40. totalcustomerSalesWithoutTax = 0;
  41. totalCustomerDiscounts = 0;
  42. while (action != 'q' && action != 'Q') // Outer Loop
  43. {
  44. if (action == 'c' || action == 'C')
  45. {
  46. customerFinished = false;
  47. checkedOut = 0;
  48. totalDiscount = 0;
  49. totalSale = 0;
  50. customerNumber++;
  51. while (!customerFinished)
  52. {
  53. bookCost = 0;
  54. while (bookCost <= 0)
  55. {
  56. cout << "Customer " << customerNumber << endl;
  57. cout << endl;
  58. cout << "Enter the cost of book: " << endl;
  59. cin >> bookCost;
  60. }
  61.  
  62. checkedOut++;
  63. char bookCover; // type of book cover hard/paper
  64.  
  65. cout << "Enter \"h\" for HARD COPY, any other key for PAPER_COPY: " << endl;
  66. cin >> bookCover;
  67.  
  68. if (bookCover == 'h' || bookCover == 'H')
  69. {
  70. bookCost += HARD_COPY;
  71. //cout << bookCost << endl;
  72. }
  73. else {
  74. bookCost += PAPER_COPY;
  75. }
  76.  
  77. totalSale += bookCost;
  78.  
  79. char discount;
  80. cout << "Enter \"d\" if customer receives a discount, any other key if they don't:" << endl;
  81. cin >> discount;
  82. if (discount == 'd' || discount == 'D')
  83. {
  84. discountAmount = DISCOUNT_RATE * bookCost;
  85. totalDiscount += discountAmount;
  86. }
  87.  
  88. char checkout; // Customer wants to check out
  89. cout << "Enter \"c\" to check out another book, any other key to total Customer " << customerNumber << ":" << endl;
  90. cin >> checkout;
  91.  
  92.  
  93. if (checkout != 'c' && checkout != 'C')
  94. {
  95. customerFinished = true;
  96. float totalsaleDiscount = (totalSale - totalDiscount);
  97. customerCost = (totalSale - totalDiscount) * (1.0 * TAX_RATE);
  98. float customerCostTax = customerCost + totalsaleDiscount;
  99. cout << endl;
  100. cout << "Customer " << customerNumber << ":" << endl;
  101. cout << "Total books checked out: " << checkedOut << endl;
  102. cout << "Total before tax and discount: " << totalSale << endl;
  103. cout << "Total Sale for Customer " << customerNumber << ": " << customerCostTax << endl;
  104. cout << endl;
  105. if (totalSale >= MaxcustomerSale)
  106. {
  107. MaxcustomerSale = totalSale;
  108. }
  109. totalcustomerSalesWithoutTax += (totalSale - totalDiscount);
  110. totalCustomerDiscounts += totalDiscount;
  111. }
  112.  
  113. }
  114.  
  115. }
  116. cout << "Welcome to Book Store. " << endl;
  117. cout << "Enter \"c\" to checkout a new customer, or \"q\" to close batch and print a daily report. " << endl;
  118. cin >> action;
  119.  
  120.  
  121.  
  122. }
  123. //For the daily report
  124. float taxAmount = totalcustomerSalesWithoutTax * TAX_RATE;
  125. float avgSale = totalcustomerSalesWithoutTax / (float)customerNumber;
  126. cout << "Average customer sale: " << avgSale << endl;
  127. cout << "Max customer sale: " << MaxcustomerSale << endl;
  128. cout << "Total customer sale (without tax): " << totalcustomerSalesWithoutTax << endl;
  129. cout << "Total daily sales: " << totalcustomerSalesWithoutTax + taxAmount << endl;
  130. cout << "Tax: " << taxAmount << endl;
  131. cout << "Discount: " << totalCustomerDiscounts << endl;
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139. cin.get();
  140. cin.get();
  141.  
  142. return 0;
  143.  
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement