Advertisement
Guest User

Improved TSHIRT Program

a guest
Oct 18th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3.  
  4. /*
  5. Programmer: Bryan Virgil
  6. Date: 10 04 2017
  7. Description: Tshirt company is giving the following discounts
  8. 1..5 --> 0% discounts
  9. 6..10 --> 10% discounts
  10. 10+ --> 25% discounts*/
  11.  
  12. using namespace std;
  13.  
  14. const int TSHIRT_PRICE = 10;
  15. const double DISCOUNT_5_PCT = 0.05;
  16. const double DISCOUNT_10_PCT = 0.10;
  17. const double DISCOUNT_15_PCT = 0.15;
  18. const double DISCOUNT_20_PCT = 0.20;
  19. const double DISCOUNT_25_PCT = 0.25;
  20.  
  21. int main()
  22. {
  23.  
  24. int numTShirts; // used to hold number of thisrts purchased
  25. double discount = 0;
  26.  
  27.  
  28. cout << "How many T-Shirts did you purchase:";
  29. cin >> numTShirts;
  30. if (cin.fail())
  31. {
  32. cout << "Wrong data type, please run the program" << endl;
  33. }
  34. else
  35. {
  36. if (numTShirts < 1)
  37. {
  38. cout << "Invalid quantity, please run the program again" << endl;
  39. cout << "Exiting..." << endl;
  40. // exit(EXIT_FAILURE);
  41. // use else statement to get rid of EXIT_FAILURE
  42. }
  43. // get rid of the exit and implement the else part
  44. // else
  45.  
  46. else
  47. switch(numTShirts)
  48. {
  49. case 1 ... 5:
  50. totalPrie - numTShirts * TSHIRT_PRICE + discount;
  51. cout << "You get 0% discount" << endl;
  52. break;
  53. case 6 ... 10:
  54. cout << "You get 5% discount" << endl;
  55. subtotal = numTShirts * TSHIRT_PRICE;
  56. discount = subTotal * DISCOUNT_5_PCT;
  57. totalPrice = subTotal - discount;
  58. break;
  59. case 11 ... 20:
  60. cout << "You get 10% discount" << endl;
  61. subtotal = numTShirts * TSHIRT_PRICE;
  62. discount = subTotal * DISCOUNT_10_PCT;
  63. totalPrice = subTotal - discount;
  64. break;
  65. case 21 ... 50:
  66. cout << "You get 15% discount" << endl;
  67. subtotal = numTShirts * TSHIRT_PRICE;
  68. discount = subTotal * DISCOUNT_15_PCT;
  69. totalPrice = subTotal - discount;
  70. break;
  71. case 51 ... 100:
  72. cout << "You get 20% discount" << endl;
  73. subtotal = numTShirts * TSHIRT_PRICE;
  74. discount = subTotal * DISCOUNT_20_PCT;
  75. totalPrice = subTotal - discount;
  76. break;
  77. default:
  78. cout << "Call for discount" << endl;
  79. }
  80.  
  81. cout << "You purchased: " << numTShirts << endl;
  82. cout << "Your subtotal was $: " << subTotal << endl;
  83. cout << "Your discount was $: " << discount << endl;
  84. cout << "Your total price was $ " << totalPrice << endl;
  85. cout << "" <<
  86. }
  87. return 0;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement