elena1234

DistanceCalculator

Oct 13th, 2020 (edited)
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.16 KB | None | 0 0
  1. using System;
  2.  
  3. namespace DistanceCalculator
  4. {
  5.     class MainClass
  6.     {
  7.         public static void Main(string[] args)
  8.         {
  9.             int allStepsMade = int.Parse(Console.ReadLine());
  10.             double lenghOfOneStepInCentimetres = double.Parse(Console.ReadLine());
  11.             int distanceNeedToTravelInMeters = int.Parse(Console.ReadLine());
  12.             double distanceNeedToTravelInCentimetres = distanceNeedToTravelInMeters * 100;
  13.             double lengOfEveryFifthStep = lenghOfOneStepInCentimetres - (0.3 * lenghOfOneStepInCentimetres);        
  14.             double shorterSteps = 0;
  15.  
  16.             if (allStepsMade >= 5)
  17.             {
  18.                 shorterSteps = Math.Truncate((double) allStepsMade / 5);
  19.             }
  20.  
  21.             double normalSteps = allStepsMade - shorterSteps;
  22.             double madeDistanceInCentimetres = (normalSteps * lenghOfOneStepInCentimetres) + (shorterSteps * lengOfEveryFifthStep);
  23.             double percentageOfDistance = madeDistanceInCentimetres / distanceNeedToTravelInCentimetres * 100;
  24.             Console.WriteLine($"You travelled {percentageOfDistance:F2}% of the distance!");
  25.         }
  26.       }
  27.     }
  28.  
Add Comment
Please, Sign In to add comment