Advertisement
silvana1303

walking

Apr 11th, 2020
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.12 KB | None | 0 0
  1. using System;
  2.  
  3. namespace homeworkloops2
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             // 10 000 steps a day
  10.             // when tired == Going home
  11.             // if steps >= 10 000 == goal reached
  12.             // diff between goal and steps == more steps to reach goal
  13.  
  14.             int goal = 10000;
  15.             int sum = 0;
  16.             Boolean lastSteps = false;
  17.  
  18.             while (true)
  19.             {
  20.                 string steps = Console.ReadLine();
  21.  
  22.                 if ("Going home" == steps)
  23.                 {
  24.                     lastSteps = true;
  25.                     continue;
  26.  
  27.                 }
  28.  
  29.                 int num = int.Parse(steps);
  30.                 sum += num;
  31.  
  32.                 if (sum >= goal || lastSteps)
  33.                 {
  34.                     break;
  35.                 }
  36.             }
  37.  
  38.             if (sum >= goal)
  39.             {
  40.                 Console.WriteLine("Goal reached! Good job!");
  41.             }
  42.             else
  43.             {
  44.                 Console.WriteLine($"{goal - sum} more steps to reach goal.");
  45.             }
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement