Advertisement
Spocoman

Cruise Ship

Oct 7th, 2023
644
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.17 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.  
  8.     string destination, cabinType;
  9.     getline(cin, destination);
  10.     getline(cin, cabinType);
  11.  
  12.     int overnights;
  13.     cin >> overnights;
  14.  
  15.     double dayPrice = 0;
  16.  
  17.     if (destination == "Mediterranean") {
  18.         if (cabinType == "standard cabin") {
  19.             dayPrice = 27.50;
  20.         }
  21.         else if (cabinType == "cabin with balcony") {
  22.             dayPrice = 30.20;
  23.         }
  24.         else {
  25.             dayPrice = 40.50;
  26.         }
  27.     }
  28.     else if (destination == "Adriatic") {
  29.         if (cabinType == "standard cabin") {
  30.             dayPrice = 22.99;
  31.         }
  32.         else if (cabinType == "cabin with balcony") {
  33.             dayPrice = 25.00;
  34.         }
  35.         else {
  36.             dayPrice = 34.99;
  37.         }
  38.     }
  39.     else {
  40.         if (cabinType == "standard cabin") {
  41.             dayPrice = 23.00;
  42.         }
  43.         else if (cabinType == "cabin with balcony") {
  44.             dayPrice = 26.60;
  45.         }
  46.         else {
  47.             dayPrice = 39.80;
  48.         }
  49.     }
  50.  
  51.     double totalSum = dayPrice * 4 * overnights;
  52.     if (overnights > 7) {
  53.         totalSum *= 0.75;
  54.     }
  55.  
  56.     printf("Annie's holiday in the %s sea costs %.2f lv.\n", destination.c_str(), totalSum);
  57.     return 0;
  58. }
  59.  
  60. РЕШЕНИЕ С ТЕРНАРЕН ОПЕРАТОР:
  61.  
  62. #include <iostream>
  63. #include <string>
  64.  
  65. using namespace std;
  66.  
  67. int main() {
  68.  
  69.     string destination, cabinType;
  70.     getline(cin, destination);
  71.     getline(cin, cabinType);
  72.  
  73.     int overnights;
  74.     cin >> overnights;
  75.  
  76.     double dayPrice =
  77.         destination == "Mediterranean" ?
  78.         (cabinType == "standard cabin" ? 27.50 : cabinType == "cabin with balcony" ? 30.20 : 40.50) :
  79.         destination == "Adriatic" ?
  80.         (cabinType == "standard cabin" ? 22.99 : cabinType == "cabin with balcony" ? 25.00 : 34.99) :
  81.         (cabinType == "standard cabin" ? 23.00 : cabinType == "cabin with balcony" ? 26.60 : 39.80);
  82.  
  83.     double totalSum = dayPrice * 4 * overnights * (overnights > 7 ? 0.75 : 1);
  84.  
  85.     printf("Annie's holiday in the %s sea costs %.2f lv.\n", destination.c_str(), totalSum);
  86.     return 0;
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement