Advertisement
SmellyBadger

Untitled

Oct 18th, 2018
114
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. cout << endl;
  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 << "Enter the cost of book: " << endl;
  58. cin >> bookCost;
  59. }
  60.  
  61. checkedOut++;
  62. char bookCover; // type of book cover hard/paper
  63.  
  64. cout << "Enter \"h\" for HARD COPY, any other key for PAPER_COPY: " << endl;
  65. cin >> bookCover;
  66.  
  67. if (bookCover == 'h' || bookCover == 'H')
  68. {
  69. bookCost += HARD_COPY;
  70. //cout << bookCost << endl;
  71. }
  72. else {
  73. bookCost += PAPER_COPY;
  74. }
  75.  
  76. totalSale += bookCost;
  77.  
  78. char discount;
  79. cout << "Enter \"d\" if customer receives a discount, any other key if they don't:" << endl;
  80. cin >> discount;
  81. if (discount == 'd' || discount == 'D')
  82. {
  83. discountAmount = DISCOUNT_RATE * bookCost;
  84. totalDiscount += discountAmount;
  85. }
  86.  
  87. char checkout; // Customer wants to check out
  88. cout << "Enter \"c\" to check out another book, any other key to total Customer " << customerNumber << ":" << endl;
  89. cin >> checkout;
  90. cout << endl;
  91.  
  92. if (checkout != 'c' && checkout != 'C')
  93. {
  94. customerFinished = true;
  95. float totalsaleDiscount = (totalSale - totalDiscount);
  96. customerCost = (totalSale - totalDiscount) * (1.0 * TAX_RATE);
  97. float customerCostTax = customerCost + totalsaleDiscount;
  98. cout << "Customer " << customerNumber << ":" << endl;
  99. cout << "Total books checked out: " << checkedOut << endl;
  100. cout << "Total before tax and discount: " << totalSale << endl;
  101. cout << "Total Sale for Customer " << customerNumber << ": " << customerCostTax << endl;
  102. cout << endl;
  103. if (totalSale >= MaxcustomerSale)
  104. {
  105. MaxcustomerSale = totalSale;
  106. }
  107. totalcustomerSalesWithoutTax += (totalSale - totalDiscount);
  108. totalCustomerDiscounts += totalDiscount;
  109. }
  110.  
  111. }
  112.  
  113. }
  114. cout << "Welcome to Book Store. " << endl;
  115. cout << "Enter \"c\" to checkout a new customer, or \"q\" to close batch and print a daily report. " << endl;
  116. cin >> action;
  117. cout << endl;
  118.  
  119.  
  120. }
  121. //For the daily report
  122. float taxAmount = totalcustomerSalesWithoutTax * TAX_RATE;
  123. float avgSale = totalcustomerSalesWithoutTax / (float)customerNumber;
  124. cout << "Average customer sale: " << avgSale << endl;
  125. cout << "Max customer sale: " << MaxcustomerSale << endl;
  126. cout << "Total customer sale (without tax): " << totalcustomerSalesWithoutTax << endl;
  127. cout << "Total daily sales: " << totalcustomerSalesWithoutTax + taxAmount << endl;
  128. cout << "Tax: " << taxAmount << endl;
  129. cout << "Discount: " << totalCustomerDiscounts << endl;
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137. cin.get();
  138. cin.get();
  139.  
  140. return 0;
  141.  
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement