Advertisement
Spocoman

08. Cinema Ticket

Sep 4th, 2023
827
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 1 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     string dayOfWeek;
  7.     cin >> dayOfWeek;
  8.  
  9.     int price = 0;
  10.  
  11.     if (dayOfWeek == "Monday" || dayOfWeek == "Tuesday" || dayOfWeek == "Friday") {
  12.         price = 12;
  13.     }
  14.     else if (dayOfWeek == "Wednesday" || dayOfWeek == "Thursday") {
  15.         price = 14;
  16.     }
  17.     else {
  18.         price = 16;
  19.     }
  20.     cout << price << endl;
  21.    
  22.     return 0;
  23. }
  24.  
  25. Решение с тернарен оператор:
  26.  
  27. #include <iostream>
  28.  
  29. using namespace std;
  30.  
  31. int main() {
  32.     string dayOfWeek;
  33.     cin >> dayOfWeek;
  34.  
  35.     int price =
  36.         dayOfWeek == "Saturday" || dayOfWeek == "Sunday" ? 16 :
  37.         dayOfWeek == "Wednesday" || dayOfWeek == "Thursday" ? 14 : 12;
  38.  
  39.     cout << price << endl;
  40.  
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement