Advertisement
desislava_topuzakova

04. Walking

May 19th, 2020
1,386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.29 KB | None | 0 0
  1. using System;
  2.  
  3. namespace While
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             //команда -> Going home или стъпки под формата на string("1000")
  10.             //стоп: стъпките >= 10000
  11.             //продължаваме: стъпки < 10000
  12.  
  13.            
  14.             int steps = 0;
  15.  
  16.             while (steps < 10000)
  17.             {
  18.                 //команда
  19.                 string command = Console.ReadLine();
  20.                 //проверка
  21.                 if (command == "Going home")
  22.                 {
  23.                     int stepsToHome = int.Parse(Console.ReadLine());
  24.                     steps += stepsToHome;
  25.                     break;
  26.  
  27.                 }
  28.                 else
  29.                 {
  30.                     //число под формата на стринг -> "1500"
  31.                     int walkedSteps = int.Parse(command);
  32.                     steps += walkedSteps;
  33.                 }
  34.             }
  35.  
  36.             if (steps >= 10000)
  37.             {
  38.                 Console.WriteLine("Goal reached! Good job!");
  39.             }
  40.             else
  41.             {
  42.                 Console.WriteLine($"{10000 - steps} more steps to reach goal.");
  43.             }
  44.  
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement