Advertisement
silvana1303

distance calculator

Jun 16th, 2020
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.94 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Threading;
  6.  
  7. namespace ConsoleApp1
  8. {
  9.     class Exam
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             double steps = double.Parse(Console.ReadLine());
  14.             double lenghtSteps = double.Parse(Console.ReadLine());
  15.             double distance = double.Parse(Console.ReadLine());
  16.  
  17.             double sumSteps = 0;
  18.  
  19.             for (int i = 1; i <= steps; i++)
  20.             {
  21.                 if (i % 5 == 0)
  22.                 {
  23.                     sumSteps += lenghtSteps * 0.70;
  24.                 }
  25.                 else
  26.                 {
  27.                     sumSteps += lenghtSteps;
  28.                 }
  29.             }
  30.  
  31.             sumSteps /= 100;
  32.             double percentage = sumSteps / distance * 100.0;
  33.  
  34.             Console.WriteLine($"You travelled {percentage:f2}% of the distance!");
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement