Advertisement
Spocoman

Oscars week in cinema

Sep 21st, 2023 (edited)
601
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.45 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     string movieName,typeOfHall;
  8.     getline(cin, movieName);
  9.     getline(cin, typeOfHall);
  10.    
  11.     int ticketCount;
  12.     cin >> ticketCount;
  13.  
  14.     double ticketPrice = 0;
  15.  
  16.     if (movieName == "A Star Is Born") {
  17.         if (typeOfHall == "normal") {
  18.             ticketPrice = 7.50;
  19.         }
  20.         else if (typeOfHall == "luxury") {
  21.             ticketPrice = 10.50;
  22.         }
  23.         else if (typeOfHall == "ultra luxury") {
  24.             ticketPrice = 13.50;
  25.         }
  26.     }
  27.     else if (movieName == "Bohemian Rhapsody") {
  28.         if (typeOfHall == "normal"){
  29.             ticketPrice = 7.35;
  30.         }
  31.         else if (typeOfHall == "luxury") {
  32.             ticketPrice = 9.45;
  33.         }
  34.         else if (typeOfHall == "ultra luxury") {
  35.             ticketPrice = 12.75;
  36.         }
  37.     }
  38.     else if (movieName == "Green Book") {
  39.         if (typeOfHall == "normal") {
  40.             ticketPrice = 8.15;
  41.         }
  42.         else if (typeOfHall == "luxury") {
  43.             ticketPrice = 10.25;
  44.         }
  45.         else if (typeOfHall == "ultra luxury") {
  46.             ticketPrice = 13.25;
  47.         }
  48.     }
  49.     else if (movieName == "The Favourite") {
  50.         if (typeOfHall == "normal") {
  51.             ticketPrice = 8.75;
  52.         }
  53.         else if (typeOfHall == "luxury") {
  54.             ticketPrice = 11.55;
  55.         }
  56.         else if (typeOfHall == "ultra luxury") {
  57.             ticketPrice = 13.95;
  58.         }
  59.     }
  60.  
  61.     printf("%s -> %.2f lv.\n", movieName.c_str(), ticketPrice * ticketCount);
  62.  
  63.     return 0;
  64.  
  65. Решение с тернарен оператор:
  66.  
  67. #include <iostream>
  68. #include <string>
  69.  
  70. using namespace std;
  71.  
  72. int main() {
  73.     string movieName,typeOfHall;
  74.     getline(cin, movieName);
  75.     getline(cin, typeOfHall);
  76.    
  77.     int ticketCount;
  78.     cin >> ticketCount;
  79.  
  80.     double ticketPrice =
  81.         movieName == "A Star Is Born" ? (typeOfHall == "normal" ? 7.50 : typeOfHall == "luxury" ? 10.50 : 13.50) :
  82.         movieName == "Bohemian Rhapsody" ? (typeOfHall == "normal" ? 7.35 : typeOfHall == "luxury" ? 9.45 : 12.75) :
  83.         movieName == "Green Book" ? (typeOfHall == "normal" ? 8.15 : typeOfHall == "luxury" ? 10.25 : 13.25) :
  84.         movieName == "The Favourite" ? (typeOfHall == "normal" ? 8.75 : typeOfHall == "luxury" ? 11.55 : 13.95) : 0;
  85.  
  86.     printf("%s -> %.2f lv.\n", movieName.c_str(), ticketPrice * ticketCount);
  87.  
  88.     return 0;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement