manytimes-3

Untitled

Nov 9th, 2018
1,106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.22 KB | None | 0 0
  1. <?php
  2.  
  3. $budget = doubleval(readline());
  4. $decoration = readline();
  5.  
  6. $price = 0;
  7. $spentMoney = 0;
  8. $balloons = 0;
  9. $flowers = 0;
  10. $candles = 0;
  11. $ribbon = 0;
  12.  
  13. while ($decoration != "stop") {
  14.     $itemsCount = intval(readline());
  15.  
  16.     switch ($decoration) {
  17.         case "balloons":
  18.             $price = $itemsCount * 0.1;
  19.             $balloons += $itemsCount;
  20.             break;
  21.         case "flowers":
  22.             $price = $itemsCount * 1.5;
  23.             $flowers += $itemsCount;
  24.             break;
  25.         case "candles":
  26.             $price = $itemsCount * 0.5;
  27.             $candles += $itemsCount;
  28.             break;
  29.         case "ribbon":
  30.             $price = $itemsCount * 2;
  31.             $ribbon += $itemsCount;
  32.             break;
  33.         default:
  34.             break;
  35.     }
  36.  
  37.     $budget -= $price;
  38.     $spentMoney += $price;
  39.  
  40.     if ($price > $budget) {
  41.         print "All money is spent!\n";
  42.         break;
  43.     }
  44.  
  45.     $decoration = readline();
  46.  
  47.     if ($decoration == "stop") {
  48.         printf("Spend money: %.2f\n", $spentMoney);
  49.         printf("Money left: %.2f\n", $budget);
  50.     }
  51. }
  52.  
  53. print "Purchased decoration is $balloons balloons, $ribbon m ribbon, $flowers flowers and $candles candles.";
Advertisement
Add Comment
Please, Sign In to add comment