Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $input = readline();
- $money = 0;
- while ($input !== "Start") {
- $coin = $input == 1 || $input == 2 || $input == 0.1 || $input == 0.2 || $input == 0.5 ? floatval($input) : 0;
- $output = $coin === 0 ? "Cannot accept " . $input . PHP_EOL : '';
- echo $output;
- $money += $coin;
- $input = readline();
- }
- $input = readline();
- while ($input !== "End") {
- $spending = round($input === "Nuts" ? 2 : ($input === "Water" ? 0.7 : ($input == "Crisps" ? 1.5 : ($input === "Soda" ? 0.8 : ($input === "Coke" ? 1 : 0)))), 2);
- $output = $spending == 0 ? "Invalid product\n" : ($spending > round($money, 2) ? "Sorry, not enough money\n" : "Purchased " . strtolower($input) . PHP_EOL);
- echo $output;
- $money -= $spending > round($money, 2) ? 0 : round($spending, 2);
- $input = readline();
- }
- echo "Change: " . number_format($money, 2, '.', '');
Add Comment
Please, Sign In to add comment