Advertisement
Spocoman

Energy Booster

Sep 18th, 2023
598
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.04 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.    
  8.     string fruit, fruitSize;
  9.     cin >> fruit >> fruitSize;
  10.  
  11.     int fruitCount;
  12.     cin >> fruitCount;
  13.  
  14.     double fruitPrice = 0;
  15.  
  16.     if (fruit == "Watermelon") {
  17.         if (fruitSize == "small") {
  18.             fruitPrice = 56;
  19.         }
  20.         else {
  21.             fruitPrice = 28.70;
  22.         }
  23.     }
  24.     else if (fruit == "Mango") {
  25.         if (fruitSize == "small") {
  26.             fruitPrice = 36.66;
  27.         }
  28.         else {
  29.             fruitPrice = 19.60;
  30.         }
  31.     }
  32.     else if (fruit == "Pineapple") {
  33.         if (fruitSize == "small") {
  34.             fruitPrice = 42.10;
  35.         }
  36.         else {
  37.             fruitPrice = 24.80;
  38.         }
  39.     }
  40.     else if (fruit == "Raspberry") {
  41.         if (fruitSize == "small") {
  42.             fruitPrice = 20;
  43.         }
  44.         else {
  45.             fruitPrice = 15.20;
  46.         }
  47.     }
  48.  
  49.     if (fruitSize == "small") {
  50.         fruitPrice *= 2;
  51.     }
  52.     else {
  53.         fruitPrice *= 5;
  54.     }
  55.  
  56.     double total = fruitPrice * fruitCount;
  57.  
  58.     if (total >= 400 && total <= 1000) {
  59.         total *= 0.85;
  60.     }
  61.     else if (total > 1000) {
  62.         total /= 2;
  63.     }
  64.  
  65.     printf("%.2f lv.\n", total);
  66.  
  67.     return 0;
  68. }
  69.  
  70. РЕШЕНИЕ С ТЕРНАРЕН ОПЕРАТОР:
  71.  
  72. #include <iostream>
  73. #include <string>
  74.  
  75. using namespace std;
  76.  
  77. int main() {
  78.    
  79.     string fruit, fruitSize;
  80.     cin >> fruit >> fruitSize;
  81.  
  82.     int fruitCount;
  83.     cin >> fruitCount;
  84.  
  85.     double fruitPrice =
  86.         (fruit == "Watermelon" ? (fruitSize == "small" ? 56 : 28.70) :
  87.             fruit == "Mango" ? (fruitSize == "small" ? 36.66 : 19.60) :
  88.             fruit == "Pineapple" ? (fruitSize == "small" ? 42.10 : 24.80) :
  89.             fruit == "Raspberry" ? (fruitSize == "small" ? 20 : 15.20) : 0)
  90.         * (fruitSize == "small" ? 2 : 5);
  91.  
  92.     double total = fruitPrice * fruitCount;
  93.  
  94.     total *= total > 1000 ? 0.5 : total >= 400 ? 0.85 : 1;
  95.  
  96.     printf("%.2f lv.\n", total);
  97.  
  98.     return 0;
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement