Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $currentBalance = floatval(readline());
- $totalSpend = 0;
- while (true){
- $game = readline();
- if ($game === "Game Time"){
- break;
- }
- $price = 0;
- switch ($game){
- case "OutFall 4": $price = 39.99; break;
- case "CS: OG": $price = 15.99; break;
- case "Zplinter Zell": $price = 19.99; break;
- case "Honored 2": $price = 59.99; break;
- case "RoverWatch": $price = 29.99; break;
- case "RoverWatch Origins Edition": $price = 39.99; break;
- default:
- echo "Not Found".PHP_EOL;
- break;
- }
- if ($price > $currentBalance){
- echo "Too Expensive".PHP_EOL;
- } elseif ($price > 0) {
- $totalSpend += $price;
- $currentBalance -= $price;
- echo "Bought $game".PHP_EOL;
- }
- if (number_format(($currentBalance), 2, ".", "") === 0.00){
- echo "Out of money!".PHP_EOL;
- return;
- }
- }
- printf("Total spent: $%.2f. Remaining: $%.2f", $totalSpend, $currentBalance);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement