Advertisement
Spocoman

Pastry Shop

Sep 21st, 2023
643
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     string type;
  8.     cin >> type;
  9.  
  10.     double quantity, date;
  11.     cin >> quantity >> date;
  12.  
  13.     double price = 0;
  14.  
  15.     if (date <= 15) {
  16.         if (type == "Cake") {
  17.             price = 24.00;
  18.         }
  19.         else if (type == "Souffle") {
  20.             price = 6.66;
  21.         }
  22.         else {
  23.             price = 12.60;
  24.         }
  25.     }
  26.     else {
  27.         if (type == "Cake") {
  28.             price = 28.70;
  29.         }
  30.         else if (type == "Souffle") {
  31.             price = 9.80;
  32.         }
  33.         else {
  34.             price = 16.98;
  35.         }
  36.     }
  37.  
  38.     double sum = price * quantity;
  39.  
  40.     if (date <= 22) {
  41.         if (sum >= 100 && sum <= 200) {
  42.             sum -= sum * 0.15;
  43.         }
  44.         else if (sum > 200) {
  45.             sum -= sum * 0.25;
  46.         }
  47.     }
  48.  
  49.     if (date <= 15) {
  50.         sum -= sum * 0.10;
  51.     }
  52.  
  53.     cout << fixed << setprecision(2) << sum << endl;
  54.     return 0;
  55. }
  56.  
  57. Решение с тернарен оператор:
  58.  
  59. #include <iostream>
  60. #include <iomanip>
  61.  
  62. using namespace std;
  63.  
  64. int main() {
  65.     string type;
  66.     cin >> type;
  67.  
  68.     double quantity, date;
  69.     cin >> quantity >> date;
  70.  
  71.     double sum =
  72.         (date <= 15 ? (type == "Cake" ? 24.00 : type == "Souffle" ? 6.66 : 12.60) :
  73.             (type == "Cake" ? 28.70 : type == "Souffle" ? 9.80 : 16.98)) * quantity;
  74.  
  75.     sum *= date <= 22 ? (sum > 200 ? 0.75 : sum >= 100 ? 0.85 : 1) : 1;
  76.  
  77.     if (date <= 15) {
  78.         sum *= 0.90;
  79.     }
  80.  
  81.     cout << fixed << setprecision(2) << sum << endl;
  82.     return 0;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement