Advertisement
Spocoman

Excursion Calculator

Sep 18th, 2023
854
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.27 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     int personCount;
  8.     cin >> personCount;
  9.  
  10.     string season;
  11.     cin >> season;
  12.  
  13.     double personPrice = 0;
  14.  
  15.     if (season == "spring") {
  16.         if (personCount <= 5) {
  17.             personPrice = 50.00;
  18.         }
  19.         else {
  20.             personPrice = 48.00;
  21.         }
  22.     }
  23.     else if (season == "summer") {
  24.         if (personCount <= 5) {
  25.             personPrice = 48.50;
  26.         }
  27.         else {
  28.             personPrice = 45.00;
  29.         }
  30.     }
  31.     else if (season == "autumn")
  32.     {
  33.         if (personCount <= 5) {
  34.             personPrice = 60.00;
  35.         }
  36.         else {
  37.             personPrice = 49.50;
  38.         }
  39.     }
  40.     else {
  41.         if (personCount <= 5) {
  42.             personPrice = 86.00;
  43.         }
  44.         else {
  45.             personPrice = 85.00;
  46.         }
  47.     }
  48.  
  49.     if (season == "summer") {
  50.         personPrice *= 0.85;
  51.     }
  52.     else if (season == "winter") {
  53.         personPrice *= 1.08;
  54.     }
  55.  
  56.     printf("%.2f leva.", personPrice * personCount);
  57.  
  58.     return 0;
  59. }
  60.  
  61. РЕШЕНИЕ С ТЕРНАРЕН ОПЕРАТОР:
  62.  
  63. #include <iostream>
  64. #include <string>
  65.  
  66. using namespace std;
  67.  
  68. int main() {
  69.     int personCount;
  70.     cin >> personCount;
  71.  
  72.     string season;
  73.     cin >> season;
  74.  
  75.     double personPrice =
  76.         season == "spring" ? (personCount <= 5 ? 50.00 : 48.00) :
  77.         season == "summer" ? (personCount <= 5 ? 48.50 : 45.00) :
  78.         season == "autumn" ? (personCount <= 5 ? 60.00 : 49.50) :
  79.         (personCount <= 5 ? 86.00 : 85.00);
  80.  
  81.     personPrice *= season == "summer" ? 0.85 : season == "winter" ? 1.08 : 1;
  82.  
  83.     printf("%.2f leva.", personPrice * personCount);
  84.  
  85.     return 0;
  86. }
  87.  
  88. ИЛИ:
  89.  
  90. #include <iostream>
  91. #include <string>
  92.  
  93. using namespace std;
  94.  
  95. int main() {
  96.     int personCount;
  97.     cin >> personCount;
  98.  
  99.     string season;
  100.     cin >> season;
  101.  
  102.     double personPrice =
  103.         season == "spring" ? (personCount <= 5 ? 50.00 : 48.00) :
  104.         season == "summer" ? (personCount <= 5 ? 48.50 : 45.00) * 0.85:
  105.         season == "autumn" ? (personCount <= 5 ? 60.00 : 49.50) :
  106.         (personCount <= 5 ? 86.00 : 85.00) * 1.08;
  107.  
  108.     printf("%.2f leva.", personPrice * personCount);
  109.  
  110.     return 0;
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement