Advertisement
Spocoman

Film Premiere

Sep 18th, 2023
815
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.75 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     string movie, pack;
  8.     getline(cin, movie);
  9.     cin >> pack;
  10.  
  11.     int tickets;
  12.     cin >> tickets;
  13.  
  14.     double sum = 0;
  15.  
  16.     if (movie == "John Wick") {
  17.         if (pack == "Drink") {
  18.             sum = 12;
  19.         }
  20.         else if (pack == "Popcorn") {
  21.             sum = 15;
  22.         }
  23.         else {
  24.             sum = 19;
  25.         }
  26.     }
  27.     else if (movie == "Star Wars") {
  28.         if (pack == "Drink") {
  29.             sum = 18;
  30.         }
  31.         else if (pack == "Popcorn") {
  32.             sum = 25;
  33.         }
  34.         else {
  35.             sum = 30;
  36.         }
  37.     }
  38.     else if (movie == "Jumanji") {
  39.         if (pack == "Drink") {
  40.             sum = 9;
  41.         }
  42.         else if (pack == "Popcorn") {
  43.             sum = 11;
  44.         }
  45.         else {
  46.             sum = 14;
  47.         }
  48.     }
  49.  
  50.     if (movie == "Star Wars" && tickets >= 4) {
  51.         sum *= 0.70;
  52.     }
  53.     else if (movie == "Jumanji" && tickets == 2) {
  54.         sum *= 0.85;
  55.     }
  56.  
  57.     printf("Your bill is %.2f leva.\n", sum * tickets);
  58.  
  59.     return 0;
  60. }
  61.  
  62. Решение с тернарен оператор:
  63.  
  64. #include <iostream>
  65. #include <string>
  66.  
  67. using namespace std;
  68.  
  69. int main() {
  70.     string movie, pack;
  71.     getline(cin, movie);
  72.     cin >> pack;
  73.    
  74.     int tickets;
  75.     cin >> tickets;
  76.  
  77.     double sum =
  78.         movie == "John Wick" ? (pack == "Drink" ? 12 : pack == "Popcorn" ? 15 : 19) :
  79.         movie == "Star Wars" ? (pack == "Drink" ? 18 : pack == "Popcorn" ? 25 : 30) * (tickets >= 4 ? 0.70 : 1) :
  80.         (pack == "Drink" ? 9 : pack == "Popcorn" ? 11 : 14) * (tickets == 2 ? 0.85 : 1);
  81.  
  82.     printf("Your bill is %.2f leva.\n", sum * tickets);
  83.  
  84.     return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement