Advertisement
Spocoman

Family Trip

Sep 18th, 2023 (edited)
969
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.20 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     double budget;
  8.     cin >> budget;
  9.  
  10.     int overnights;
  11.     cin >> overnights;
  12.  
  13.     double overnightPrice;
  14.     cin >> overnightPrice;
  15.  
  16.     int additionalCosts;
  17.     cin >> additionalCosts;
  18.  
  19.     if (overnights > 7) {
  20.         overnightPrice *= 0.95;
  21.     }
  22.  
  23.     budget -= overnightPrice * overnights + 0.01 * budget * additionalCosts;
  24.  
  25.     if (budget >= 0) {
  26.         printf("Ivanovi will be left with %.2f leva after vacation.\n", budget);
  27.     }
  28.     else {
  29.         printf("%.2f leva needed.\n", abs(budget));
  30.     }
  31.     return 0;
  32. }
  33.  
  34. Решение с тернарен оператор и леко тарикатската:)
  35.  
  36. #include <iostream>
  37. #include <string>
  38.  
  39. using namespace std;
  40.  
  41. int main() {
  42.     double budget, overnights, overnightPrice, additionalCosts;
  43.     cin >> budget >> overnights >> overnightPrice >> additionalCosts;
  44.  
  45.     budget -= overnightPrice * (overnights > 7 ? 0.95 : 1) * overnights + 0.01 * budget * additionalCosts;
  46.  
  47.     budget >= 0 ?
  48.         printf("Ivanovi will be left with %.2f leva after vacation.\n", budget) :
  49.         printf("%.2f leva needed.\n", abs(budget));
  50.  
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement