Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $budget = doubleval(readline());
- $decoration = readline();
- $price = 0;
- $spentMoney = 0;
- $balloons = 0;
- $flowers = 0;
- $candles = 0;
- $ribbon = 0;
- while ($decoration != "stop") {
- $itemsCount = intval(readline());
- switch ($decoration) {
- case "balloons":
- $price = $itemsCount * 0.1;
- $balloons += $itemsCount;
- break;
- case "flowers":
- $price = $itemsCount * 1.5;
- $flowers += $itemsCount;
- break;
- case "candles":
- $price = $itemsCount * 0.5;
- $candles += $itemsCount;
- break;
- case "ribbon":
- $price = $itemsCount * 2;
- $ribbon += $itemsCount;
- break;
- default:
- break;
- }
- $budget -= $price;
- $spentMoney += $price;
- if ($price > $budget) {
- print "All money is spent!\n";
- break;
- }
- $decoration = readline();
- if ($decoration == "stop") {
- printf("Spend money: %.2f\n", $spentMoney);
- printf("Money left: %.2f\n", $budget);
- }
- }
- print "Purchased decoration is $balloons balloons, $ribbon m ribbon, $flowers flowers and $candles candles.";
Advertisement
Add Comment
Please, Sign In to add comment