SHARE
TWEET

07. Fruit Shop

MartinGeorgiev Apr 20th, 2019 100 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. $fruit = readline();
  4. $day = readline();
  5. $quantity = floatval(readline());
  6.  
  7. $isFruit = $fruit == 'banana' || $fruit == 'apple' || $fruit == 'grapefruit' || $fruit == 'orange' || $fruit == 'kiwi' || $fruit == 'pineapple' || $fruit == 'grapes';
  8.  
  9. $isDayofWeek = $day == 'Monday' || $day == 'Tuesday' || $day == 'Wednesday' || $day == 'Thursday' || $day == 'Friday';
  10.  
  11. $isWeekend = $day == 'Saturday' || $day == 'Sunday';
  12.  
  13. $productPrice = 0;
  14. if ($isDayofWeek) {
  15.     if ($fruit == 'banana') {
  16.         $productPrice = 2.5;
  17.     } else if ($fruit == 'apple') {
  18.         $productPrice = 1.2;
  19.     } else if ($fruit == 'orange') {
  20.         $productPrice = 0.85;
  21.     } else if ($fruit == 'grapefruit') {
  22.         $productPrice = 1.45;
  23.     } else if ($fruit == 'kiwi') {
  24.         $productPrice = 2.7;
  25.     } else if ($fruit == 'pineapple') {
  26.         $productPrice = 5.5;
  27.     } else if ($fruit == 'pineapple') {
  28.         $productPrice = 3.85;
  29.     } else if ($fruit == 'grapes') {
  30.         $productPrice = 3.85;
  31.     }
  32. } else if ($isWeekend) {
  33.     if ($fruit == 'banana') {
  34.         $productPrice = 2.7;
  35.     } else if ($fruit == 'apple') {
  36.         $productPrice = 1.25;
  37.     } else if ($fruit == 'orange') {
  38.         $productPrice = 0.9;
  39.     } else if ($fruit == 'grapefruit') {
  40.         $productPrice = 1.6;
  41.     } else if ($fruit == 'kiwi') {
  42.         $productPrice = 3;
  43.     } else if ($fruit == 'pineapple') {
  44.         $productPrice = 5.6;
  45.     } else if ($fruit == 'pineapple') {
  46.         $productPrice = 4.20;
  47.     }
  48.     else if ($fruit == 'grapes') {
  49.         $productPrice = 4.2;
  50.     }
  51. }
  52.  
  53. if (($isDayofWeek || $isWeekend) && $isFruit) {
  54.     $totalPrice = $quantity * $productPrice;
  55.     printf("%.2f", $totalPrice);
  56. } else {
  57.     echo 'error';
  58. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top