Advertisement
Guest User

Nested conditional - Fruit_shop

a guest
Jan 30th, 2020
429
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.74 KB | None | 0 0
  1.  
  2.  
  3. #include <iostream>
  4. #include <string>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     string fruit,weekOfDay;
  10.     cin >> fruit >> weekOfDay;
  11.     double quantity;
  12.     cin >> quantity;
  13.     double price = 0.0;
  14.  
  15.    
  16.  
  17.     if (weekOfDay == "Monday" || weekOfDay == "Tuesday" || weekOfDay == "Wednesday" ||
  18.        weekOfDay == "Thursday" || weekOfDay == "Friday") {
  19.         if (fruit == "banana") {
  20.             price = 2.50;
  21.         }
  22.         else if (fruit == "apple") {
  23.             price = 1.20;
  24.         }
  25.         else if (fruit == "orange") {
  26.             price = 0.85;
  27.         }
  28.         else if (fruit == "grapefruit") {
  29.             price = 1.45;
  30.         }
  31.         else if (fruit == "kiwi") {
  32.             price = 2.70;
  33.         }
  34.         else if (fruit == "pineapple") {
  35.             price = 5.50;
  36.         }
  37.         else if (fruit == "grapes") {
  38.             price = 3.85;
  39.         }
  40.  
  41.     }
  42.     else if (weekOfDay == "Saturday" || weekOfDay == "Sunday") {
  43.         if (fruit == "banana") {
  44.             price = 2.7;
  45.         }
  46.         else if (fruit == "apple") {
  47.             price = 1.25;
  48.         }
  49.         else if (fruit == "orange") {
  50.             price = 0.9;
  51.         }
  52.         else if (fruit == "grapefruit") {
  53.             price = 1.6;
  54.         }
  55.         else if (fruit == "kiwi") {
  56.             price = 3;
  57.         }
  58.         else if (fruit == "pineapple") {
  59.             price = 5.6;
  60.         }
  61.         else if (fruit == "grapes") {
  62.             price = 4.2;
  63.         }
  64.         if (price > 0) {
  65.  
  66.         cout.setf(ios::fixed);
  67.         cout.precision(2);
  68.         cout << price * quantity << endl;
  69.            
  70.         }
  71.         else {
  72.             cout << "error" << endl;
  73.         }
  74.      
  75.     }
  76.    
  77.     return 0;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement