Stanislavgr

04. Walking_While-Loop-Excercise

Apr 6th, 2019
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 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 _04.Walking
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. int steps = 0;
  14.  
  15. while(steps < 10000)
  16. {
  17. string command = Console.ReadLine();
  18.  
  19. if(command == "Going home")
  20.  
  21. {
  22. steps += int.Parse(Console.ReadLine());
  23.  
  24. if(steps >= 10000)
  25. {
  26. Console.WriteLine("Goal reached! Good job!");
  27. }
  28. else
  29. {
  30. int diff = 10000 - steps;
  31. Console.WriteLine($"{diff} more steps to reach goal.");
  32. }
  33. }
  34. else
  35. {
  36. steps += int.Parse(command);
  37.  
  38. if(steps>= 10000)
  39. {
  40. Console.WriteLine("Goal reached! Good job!");
  41. }
  42. }
  43. }
  44. }
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment