Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iomanip>
- #include <iostream>
- #include <string>
- using namespace std;
- const char poundSign(156);
- const char dollerSign(36);
- const char euroSign(128);
- const char hashtag(35);
- double fullPriceGoods, discountedGoods, deliverycharge;
- double topay;
- double discountrate;
- double const discountrate1 = 0.8;
- double const discountrate2 = 0.7;
- double const discountrate3 = 0.5;
- int sumofcode;
- bool validCode;
- void calculateTotalDiscountedGoods();
- void toPay();
- void checkValidVoucherCode();
- int main()
- {
- cout.setf(ios::fixed);
- cout << setprecision(2);
- cout << "Order value without discout: "<< poundSign;
- cin >> fullPriceGoods;
- if (fullPriceGoods > 0)
- {
- checkValidVoucherCode();
- if (validCode == true)
- {
- cout << "Valid voucher - free delivery. \n";
- calculateTotalDiscountedGoods();
- deliverycharge = 0.00;
- cout << "Order value with discount: " << poundSign << discountedGoods << "\n";
- cout << "Delivery charge: " << poundSign << deliverycharge << "\n";
- toPay();
- cout << "To pay: " << poundSign << topay << "\n";
- }
- else
- {
- cout << "Invalid voucher. \n";
- calculateTotalDiscountedGoods();
- deliverycharge = 6.50;
- cout << "Order value with discount: " << poundSign << discountedGoods << "\n";
- cout << "Delivery charge: " << poundSign << deliverycharge << "\n";
- toPay();
- cout << "To pay: " << poundSign << topay << "\n";
- }
- }
- else
- {
- cout << "ERROR: The order value should be a positive number! \n";
- }
- system("pause");
- return 0;
- }
- void calculateTotalDiscountedGoods()
- {
- if (fullPriceGoods <= 30.00)
- {
- discountrate = discountrate1;
- }
- else if (fullPriceGoods > 30.00 && fullPriceGoods <= 60.00)
- {
- discountrate = discountrate2;
- }
- else
- {
- discountrate = discountrate3;
- }
- discountedGoods = fullPriceGoods * discountrate;
- }
- void toPay()
- {
- if (validCode == true)
- {
- topay = discountedGoods;
- }
- else
- {
- topay = discountedGoods + deliverycharge;
- }
- }
- void checkValidVoucherCode()
- {
- int voucherCode, firstNumber, secondNumber, thirdNumber, fourthNumber, total;
- total = 12;
- cout << "Voucher code: " << hashtag;
- cin >> voucherCode;
- if (voucherCode >= 1000 && voucherCode <= 9999)
- {
- firstNumber = (voucherCode % 10);
- secondNumber = ((voucherCode /10) % 10);
- thirdNumber = ((voucherCode / 100) % 10);
- fourthNumber = ((voucherCode / 1000) % 10);
- sumofcode = firstNumber + secondNumber + thirdNumber + fourthNumber;
- if (sumofcode = total)
- {
- validCode == true;
- }
- else
- {
- validCode == false;
- }
- }
- else
- {
- validCode == false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement