Advertisement
SmellyBadger

Untitled

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