Advertisement
Guest User

Untitled

a guest
Nov 16th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. #include <iomanip>
  2. #include <iostream>
  3. #include <string>
  4. using namespace std;
  5. const char poundSign(156);
  6. const char dollerSign(36);
  7. const char euroSign(128);
  8. const char hashtag(35);
  9.  
  10. double fullPriceGoods, discountedGoods, deliverycharge;
  11. double topay;
  12. double discountrate;
  13.  
  14. double const discountrate1 = 0.8;
  15. double const discountrate2 = 0.7;
  16. double const discountrate3 = 0.5;
  17.  
  18. int sumofcode;
  19.  
  20. bool validCode;
  21.  
  22. void calculateTotalDiscountedGoods();
  23. void toPay();
  24. void checkValidVoucherCode();
  25.  
  26. int main()
  27. {
  28. cout.setf(ios::fixed);
  29. cout << setprecision(2);
  30.  
  31. cout << "Order value without discout: "<< poundSign;
  32. cin >> fullPriceGoods;
  33.  
  34. if (fullPriceGoods > 0)
  35. {
  36. checkValidVoucherCode();
  37. if (validCode == true)
  38. {
  39. cout << "Valid voucher - free delivery. \n";
  40. calculateTotalDiscountedGoods();
  41. deliverycharge = 0.00;
  42. cout << "Order value with discount: " << poundSign << discountedGoods << "\n";
  43. cout << "Delivery charge: " << poundSign << deliverycharge << "\n";
  44. toPay();
  45. cout << "To pay: " << poundSign << topay << "\n";
  46. }
  47. else
  48. {
  49. cout << "Invalid voucher. \n";
  50. calculateTotalDiscountedGoods();
  51. deliverycharge = 6.50;
  52. cout << "Order value with discount: " << poundSign << discountedGoods << "\n";
  53. cout << "Delivery charge: " << poundSign << deliverycharge << "\n";
  54. toPay();
  55. cout << "To pay: " << poundSign << topay << "\n";
  56. }
  57. }
  58. else
  59. {
  60. cout << "ERROR: The order value should be a positive number! \n";
  61. }
  62. system("pause");
  63. return 0;
  64. }
  65.  
  66. void calculateTotalDiscountedGoods()
  67. {
  68. if (fullPriceGoods <= 30.00)
  69. {
  70. discountrate = discountrate1;
  71. }
  72. else if (fullPriceGoods > 30.00 && fullPriceGoods <= 60.00)
  73. {
  74. discountrate = discountrate2;
  75. }
  76. else
  77. {
  78. discountrate = discountrate3;
  79. }
  80. discountedGoods = fullPriceGoods * discountrate;
  81. }
  82.  
  83. void toPay()
  84. {
  85. if (validCode == true)
  86. {
  87. topay = discountedGoods;
  88. }
  89. else
  90. {
  91. topay = discountedGoods + deliverycharge;
  92. }
  93. }
  94.  
  95. void checkValidVoucherCode()
  96. {
  97. int voucherCode, firstNumber, secondNumber, thirdNumber, fourthNumber, total;
  98.  
  99. total = 12;
  100. cout << "Voucher code: " << hashtag;
  101. cin >> voucherCode;
  102.  
  103. if (voucherCode >= 1000 && voucherCode <= 9999)
  104. {
  105. firstNumber = (voucherCode % 10);
  106. secondNumber = ((voucherCode /10) % 10);
  107. thirdNumber = ((voucherCode / 100) % 10);
  108. fourthNumber = ((voucherCode / 1000) % 10);
  109. sumofcode = firstNumber + secondNumber + thirdNumber + fourthNumber;
  110.  
  111. if (sumofcode = total)
  112. {
  113. validCode == true;
  114. }
  115. else
  116. {
  117. validCode == false;
  118. }
  119. }
  120. else
  121. {
  122. validCode == false;
  123. }
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement