Advertisement
Spocoman

Movie Destination

Sep 20th, 2023
883
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.79 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.     string destination, season;
  11.     cin >> destination >> season;
  12.  
  13.     int days;
  14.     cin >> days;
  15.  
  16.     double daySum = 0;
  17.  
  18.     if (destination == "Dubai") {
  19.         if (season == "Winter") {
  20.             daySum = 45000;
  21.         }
  22.         else {
  23.             daySum = 40000;
  24.         }
  25.         daySum *= 0.70;
  26.     }
  27.  
  28.     else  if (destination == "Sofia") {
  29.         if (season == "Winter") {
  30.             daySum = 17000;
  31.         }
  32.         else {
  33.             daySum = 12500;
  34.         }
  35.         daySum *= 1.25;
  36.     }
  37.     else {
  38.         if (season == "Winter") {
  39.             daySum = 24000;
  40.         }
  41.         else {
  42.             daySum = 20250;
  43.         }
  44.     }
  45.  
  46.     double totalSum = daySum * days;
  47.  
  48.     if (totalSum <= budget) {
  49.         printf("The budget for the movie is enough! We have %.2f leva left!\n", budget - totalSum);
  50.     }
  51.     else {
  52.         printf("The director needs %.2f leva more!\n", totalSum - budget);
  53.     }
  54.     return 0;
  55. }
  56.  
  57.  
  58. Решение с тернарен оператор:
  59.  
  60. #include <iostream>
  61. #include <string>
  62.  
  63. using namespace std;
  64.  
  65. int main() {
  66.     double budget;
  67.     cin >> budget;
  68.  
  69.     string destination, season;
  70.     cin >> destination >> season;
  71.  
  72.     int days;
  73.     cin >> days;
  74.  
  75.     budget -=
  76.         (destination == "Dubai" ? (season == "Winter" ? 45000 : 40000) * 0.70 :
  77.         destination == "Sofia" ? (season == "Winter" ? 17000 : 12500) * 1.25 :
  78.         (season == "Winter" ? 24000 : 20250)) * days;
  79.        
  80.     budget >= 0 ?
  81.         printf("The budget for the movie is enough! We have %.2f leva left!\n", budget) :
  82.         printf("The director needs %.2f leva more!\n", abs(budget));
  83.    
  84.     return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement