Advertisement
IvetValcheva

Walking

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