Advertisement
Spocoman

04. Fishing Boat

Sep 5th, 2023
549
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. Решение с тернарен оператор:
  2.  
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.     double budget;
  9.     cin >> budget;
  10.  
  11.     string season;
  12.     cin >> season;
  13.  
  14.     int personCount;
  15.     cin >> personCount;
  16.  
  17.     const int SEASON_PRICE =
  18.         season == "Winter" ? 2600 :
  19.         season == "Spring" ? 3000 : 4200;
  20.  
  21.     const double PERSON_COUNT_DISCOUNT =
  22.         personCount > 11 ? 0.25 :
  23.         personCount > 6 ? 0.15 : 0.10;
  24.  
  25.     double sum = SEASON_PRICE * (1 - PERSON_COUNT_DISCOUNT);
  26.  
  27.     if (personCount % 2 == 0 && season != "Autumn") {
  28.         sum *= 0.95;
  29.     }
  30.  
  31.     cout.setf(ios::fixed);
  32.     cout.precision(2);
  33.  
  34.     if (budget >= sum) {
  35.         cout << "Yes! You have " << budget - sum << " leva left." << endl;
  36.     }
  37.     else {
  38.         cout << "Not enough money! You need " << sum - budget << " leva." << endl;
  39.     }
  40.  
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement