Advertisement
nevenailievaa

04.Walking

Nov 2nd, 2022
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.53 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _04.Walking
  4. {
  5.     internal class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             //INPUT
  10.             int stepsGoal = 10000;
  11.             string command = Console.ReadLine();
  12.  
  13.             int stepsSum = 0;
  14.  
  15.             //ACTION
  16.             while (true)
  17.             {
  18.                 if (command != "Going home")
  19.                 {
  20.                     int steps = int.Parse(command);
  21.  
  22.                     stepsSum += steps;
  23.  
  24.                     if (stepsSum >= stepsGoal)
  25.                     {
  26.                         Console.WriteLine("Goal reached! Good job!");
  27.                         Console.WriteLine($"{stepsSum - stepsGoal} steps over the goal!");
  28.                         return;
  29.                     }
  30.  
  31.                     command = Console.ReadLine();
  32.                 }
  33.                 else
  34.                 {
  35.                     int stepsToHome = int.Parse(Console.ReadLine());
  36.                     stepsSum += stepsToHome;
  37.  
  38.                     if (stepsSum >= stepsGoal)
  39.                     {
  40.                         Console.WriteLine("Goal reached! Good job!");
  41.                         Console.WriteLine($"{stepsSum - stepsGoal} steps over the goal!");
  42.                         return;
  43.                     }
  44.                     else
  45.                     {
  46.                         Console.WriteLine($"{stepsGoal - stepsSum} more steps to reach goal.");
  47.                         return;
  48.                     }
  49.                 }
  50.             }
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement