Advertisement
Guest User

Untitled

a guest
Oct 18th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.31 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. customerNumber = 0;
  38. MaxcustomerSale = 0;
  39. totalcustomerSalesWithoutTax = 0;
  40. totalCustomerDiscounts = 0;
  41. while (action != 'q' && action != 'Q') // Outer Loop
  42. {
  43. if (action == 'c' || action == 'C')
  44. {
  45. customerFinished = false;
  46. checkedOut = 0;
  47. totalDiscount = 0;
  48. totalSale = 0;
  49. customerNumber++;
  50. while (!customerFinished)
  51. {
  52. bookCost = 0;
  53. while (bookCost <= 0)
  54. {
  55. cout << endl;
  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.  
  91. if (checkout != 'c' && checkout != 'C')
  92. {
  93. customerFinished = true;
  94. float totalsaleDiscount = (totalSale - totalDiscount);
  95. customerCost = (totalSale - totalDiscount) * (1.0 * TAX_RATE);
  96. float customerCostTax = customerCost + totalsaleDiscount;
  97. cout << endl;
  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.  
  118.  
  119. }
  120. //For the daily report
  121. float taxAmount = totalcustomerSalesWithoutTax * TAX_RATE;
  122. float avgSale = totalcustomerSalesWithoutTax / (float)customerNumber;
  123. cout << "Average customer sale: " << avgSale << endl;
  124. cout << "Max customer sale: " << MaxcustomerSale << endl;
  125. cout << "Total customer sale (without tax): " << totalcustomerSalesWithoutTax << endl;
  126. cout << "Total daily sales: " << totalcustomerSalesWithoutTax + taxAmount << endl;
  127. cout << "Tax: " << taxAmount << endl;
  128. cout << "Discount: " << totalCustomerDiscounts << endl;
  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