SHARE
TWEET

03. Gaming Store

MartinGeorgiev Jan 31st, 2019 15 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. $startMoney = floatval(readline());
  3. $currentMoney = $startMoney;
  4.  
  5. $game = readline();
  6. $outOfMoney = false;
  7.  
  8. while ($game !== ("Game Time")) {
  9.     $gamePrice = 0;
  10.     $isValid = true;
  11.     switch ($game) {
  12.         case "OutFall 4":
  13.             $gamePrice = 39.99;
  14.             break;
  15.         case "CS: OG":
  16.             $gamePrice = 15.99;
  17.             break;
  18.         case "Zplinter Zell":
  19.             $gamePrice = 19.99;
  20.             break;
  21.         case "Honored 2":
  22.             $gamePrice = 59.99;
  23.             break;
  24.         case "RoverWatch":
  25.             $gamePrice = 29.99;
  26.             break;
  27.         case "RoverWatch Origins Edition":
  28.             $gamePrice = 39.99;
  29.             break;
  30.         default:
  31.             $isValid = false;
  32.             echo "Not Found" . PHP_EOL;
  33.             break;
  34.     }
  35.     if ($isValid) {
  36.         if ($currentMoney - $gamePrice >= 0) {
  37.             $currentMoney -= $gamePrice;
  38.             echo "Bought $game" . PHP_EOL;
  39.  
  40.             if ($currentMoney == 0) {
  41.                 echo "Out of money!" . PHP_EOL;
  42.                 $outOfMoney = true;
  43.                 break;
  44.             }
  45.         } else {
  46.             echo "Too Expensive" . PHP_EOL;
  47.         }
  48.     }
  49.  
  50.     $game = readline();
  51. }
  52.  
  53. if (!$outOfMoney) {
  54.     $totalSpend = $startMoney - $currentMoney;
  55.     printf("Total spent: $%.2f. Remaining: $%.2f" . PHP_EOL, $totalSpend, $currentMoney);
  56. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top