Advertisement
Dianov

While Loop - Exercise (04. Walking)

Dec 30th, 2020
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.42 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Walking
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string steps = "";
  14.             int stepsCounter = 0;
  15.             while (true)
  16.             {
  17.                 steps = Console.ReadLine();
  18.                 if (steps == "Going home")
  19.                 {
  20.                     steps = Console.ReadLine();
  21.                     stepsCounter += int.Parse(steps);
  22.                     if (stepsCounter < 10000)
  23.                     {
  24.                         Console.WriteLine($"{10000 - stepsCounter} more steps to reach goal.");
  25.                         break;
  26.                     }
  27.                     else if (stepsCounter >= 10000)
  28.                     {
  29.                         Console.WriteLine("Goal reached! Good job!");
  30.                         Console.WriteLine($"{stepsCounter - 10000} steps over the goal!");
  31.                         break;
  32.                     }
  33.                 }
  34.                 stepsCounter += int.Parse(steps);
  35.                 if (stepsCounter >= 10000)
  36.                 {
  37.                     Console.WriteLine("Goal reached! Good job!");
  38.                     Console.WriteLine($"{stepsCounter - 10000} steps over the goal!");
  39.                     break;
  40.                 }
  41.                
  42.             }
  43.         }
  44.     }  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement