Advertisement
avr39ripe

costDiscountGood

Sep 30th, 2020
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. int main()
  4. {
  5.     enum sumRange { rangeA = 2000, rangeB = 1500, rangeC = 1000 };
  6.     enum discount { A = 10, B = 7, C = 5};
  7.  
  8.     float haveMoney{ 0 };
  9.     float cost{ 0 };
  10.     int discountPercent{0};
  11.  
  12.  
  13.     std::cout << "Enter money sum you have\n";
  14.     std::cin >> haveMoney;
  15.  
  16.     std::cout << "Enter cost of goods you witsh to buy\n";
  17.     std::cin >> cost;
  18.  
  19.     if (cost >= rangeA)
  20.     {
  21.         discountPercent = discount::A;
  22.     }
  23.     else if ( cost >= rangeB)
  24.     {
  25.         discountPercent = discount::B;
  26.     }
  27.     else if (cost >= rangeC)
  28.     {
  29.         discountPercent = discount::C;
  30.     }
  31.    
  32.     cost -= cost * discountPercent / 100.0;
  33.  
  34.     if (discountPercent)
  35.     {
  36.         std::cout << "Cost with discount is " << cost << '\n';
  37.     }
  38.     else
  39.     {
  40.         std::cout << "Cost WITHOUT discount is " << cost << '\n';
  41.     }
  42.  
  43.     if (cost > haveMoney)
  44.     {
  45.         std::cout << "Oops! You haven't enough money to pay!\n";
  46.         std::cout << "Find another " << cost - haveMoney << " $$$ and try again!\n";
  47.     }
  48.     else
  49.     {
  50.         std::cout << "You have enough money!\n";
  51.     }
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement