Advertisement
Spocoman

11. Fruit Shop

Sep 5th, 2023
658
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     string fruit, day;
  7.     cin >> fruit >> day;
  8.  
  9.     double quantity;
  10.     cin >> quantity;
  11.  
  12.     double price = 0;
  13.  
  14.     if (day == "Monday" || day == "Tuesday" || day == "Wednesday" || day == "Thursday" || day == "Friday") {
  15.         price =
  16.             fruit == "banana" ? 2.5 :
  17.             fruit == "apple" ? 1.2 :
  18.             fruit == "orange" ? 0.85 :
  19.             fruit == "grapefruit" ? 1.45 :
  20.             fruit == "kiwi" ? 2.7 :
  21.             fruit == "pineapple" ? 5.5 :
  22.             fruit == "grapes" ? 3.85 : 0;
  23.     }
  24.     else if (day == "Saturday" || day == "Sunday") {
  25.         price =
  26.             fruit == "banana" ? 2.7 :
  27.             fruit == "apple" ? 1.25 :
  28.             fruit == "orange" ? 0.9 :
  29.             fruit == "grapefruit" ? 1.6 :
  30.             fruit == "kiwi" ? 3 :
  31.             fruit == "pineapple" ? 5.6 :
  32.             fruit == "grapes" ? 4.2 : 0;
  33.     }
  34.  
  35.     cout.setf(ios::fixed);
  36.     cout.precision(2);
  37.  
  38.     if (price > 0) {
  39.         cout << price * quantity << endl;
  40.     }
  41.     else {
  42.         cout << "error" << endl;
  43.     }
  44.  
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement