Advertisement
SmellyBadger

Untitled

Oct 18th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.71 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.  
  31. cout << "Welcome to Book Store." << endl;
  32.  
  33. cout << "Enter \"c\" to checkout a new customer, or \"q\" to close batch and print a daily report." << endl;
  34. cin >> action;
  35. cout << endl;
  36.  
  37. customerNumber = 0;
  38. while (action != 'q' && action != 'Q') // Outer Loop
  39. {
  40. if (action == 'c' || action == 'C')
  41. {
  42. customerFinished = false;
  43. checkedOut = 0;
  44. totalDiscount = 0;
  45. totalSale = 0;
  46. MaxcustomerSale = 0;
  47. totalcustomerSalesWithoutTax = 0;
  48. totalCustomerDiscounts = 0;
  49. customerNumber++;
  50. while (!customerFinished)
  51. {
  52. bookCost = 0;
  53. while (bookCost <= 0)
  54. {
  55. cout << "Customer " << customerNumber << endl;
  56. cout << "Enter the cost of book: " << endl;
  57. cin >> bookCost;
  58. }
  59.  
  60. checkedOut++;
  61. char bookCover; // type of book cover hard/paper
  62.  
  63. cout << "Enter \"h\" for HARD_COPY, any other key for PAPER_COPY: " << endl;
  64. cin >> bookCover;
  65.  
  66. if (bookCover == 'h' || bookCover == 'H')
  67. {
  68. bookCost += HARD_COPY;
  69. //cout << bookCost << endl;
  70. }
  71. else {
  72. bookCost += PAPER_COPY;
  73. }
  74.  
  75. totalSale += bookCost;
  76.  
  77. char discount;
  78. cout << "Enter \"d\" if customer receives a discount, any other key if they don't:" << endl;
  79. cin >> discount;
  80. if (discount == 'd' || discount == 'D')
  81. {
  82. discountAmount = DISCOUNT_RATE * bookCost;
  83. totalDiscount += discountAmount;
  84. }
  85.  
  86. char checkout; // Customer wants to check out
  87. cout << "Enter \"c\" to check out another book, any other key to total Customer 1: " << customerNumber << endl;
  88. cin >> checkout;
  89. cout << endl;
  90.  
  91. if (checkout != 'c' || checkout != 'C')
  92. {
  93. customerFinished = true;
  94. float customerCost = (totalSale - totalDiscount) * (1.0 * TAX_RATE);
  95. cout << "Customer " << customerNumber << ":" << endl;
  96. cout << "Total books checked out: " << checkedOut << endl;
  97. cout << "Total before tax and discount: " << totalSale << endl;
  98. cout << "Total Sale for Customer " << customerNumber << ": " << customerCost << endl;
  99. cout << endl;
  100. }
  101. if (totalSale >= MaxcustomerSale)
  102. {
  103. MaxcustomerSale = totalSale;
  104. }
  105. totalcustomerSalesWithoutTax += (totalSale - totalDiscount);
  106. totalCustomerDiscounts += totalDiscount;
  107.  
  108. }
  109.  
  110. }
  111. cout << "Welcome to Book Store. " << endl;
  112. cout << "Enter \"c\" to checkout a new customer, or \"q\" to close batch and print daily report. " << endl;
  113. cin >> action;
  114. cout << endl;
  115.  
  116. // For the daily report
  117. float taxAmount = totalcustomerSalesWithoutTax * TAX_RATE;
  118. float avgSale = totalcustomerSalesWithoutTax / (float)customerNumber;
  119. cout << "Average customer sale: " << avgSale << endl;
  120. cout << "Max customer sale:" << MaxcustomerSale << endl;
  121. cout << "Total customer sale (without tax): " << totalcustomerSalesWithoutTax << endl;
  122. cout << "Total daily sales: " << totalcustomerSalesWithoutTax + taxAmount << endl;
  123. cout << "Tax: " << taxAmount << endl;
  124. cout << "Discount: " << totalCustomerDiscounts << endl;
  125. }
  126.  
  127. //cout << "Welcome to the Book Store. " << endl;
  128. //cout << "Enter \"c\" to checkout a new customer, or \"q\" to close batch and print daily report. " << endl;
  129. //cin >> action;
  130. //cout << endl;
  131.  
  132. // For the daily report
  133. //float taxAmount = totalcustomerSalesWithoutTax * TAX_RATE;
  134. //float avgSale = totalcustomerSalesWithoutTax / (float)customerNumber;
  135. //cout << "Average customer sale: " << avgSale << endl;
  136. //cout << "Max customer sale:" << MaxcustomerSale << endl;
  137. //cout << "Total daily sales: " << totalcustomerSalesWithoutTax + taxAmount << endl;
  138. //cout << "Tax: " << taxAmount << endl;
  139. //cout << "Discount: " << totalCustomerDiscounts << endl;
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149. cin.get();
  150. cin.get();
  151.  
  152. return 0;
  153.  
  154. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement