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