Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2020
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.02 KB | None | 0 0
  1. <?php
  2.  
  3. $currentBalance = floatval(readline());
  4. $totalSpend = 0;
  5.  
  6. while (true){
  7.     $game = readline();
  8.  
  9.     if ($game === "Game Time"){
  10.         break;
  11.     }
  12.  
  13.     $price = 0;
  14.  
  15.     switch ($game){
  16.         case "OutFall 4": $price = 39.99; break;
  17.         case "CS: OG": $price = 15.99; break;
  18.         case "Zplinter Zell": $price = 19.99; break;
  19.         case "Honored 2": $price = 59.99; break;
  20.         case "RoverWatch": $price = 29.99; break;
  21.         case "RoverWatch Origins Edition": $price = 39.99; break;
  22.         default:
  23.             echo "Not Found".PHP_EOL;
  24.             break;
  25.     }
  26.  
  27.     if ($price > $currentBalance){
  28.         echo "Too Expensive".PHP_EOL;
  29.  
  30.     } elseif ($price > 0) {
  31.         $totalSpend += $price;
  32.         $currentBalance -= $price;
  33.         echo "Bought $game".PHP_EOL;
  34.     }
  35.  
  36.     if (number_format(($currentBalance), 2, ".", "") === 0.00){
  37.         echo "Out of money!".PHP_EOL;
  38.         return;
  39.     }
  40. }
  41.  
  42. printf("Total spent: $%.2f. Remaining: $%.2f", $totalSpend, $currentBalance);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement