Advertisement
MartinGeorgiev

05. Walking

Nov 25th, 2018
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.46 KB | None | 0 0
  1. <?php
  2.  
  3. $goal = 10000;
  4. $totalSteps = 0;
  5.  
  6. while ($totalSteps < $goal) {
  7.     $command = readline();
  8.     if ($command == "Going home") {
  9.         $currentSteps = intval(readline());
  10.         $totalSteps += $currentSteps;
  11.         break;
  12.     }
  13.     $currentSteps = intval($command);
  14.     $totalSteps += $currentSteps;
  15. }
  16.  
  17. if ($totalSteps >= $goal) {
  18.     echo "Goal reached! Good job!";
  19. } else {
  20.     echo ($goal - $totalSteps) . " more steps to reach goal.";
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement