Advertisement
Guest User

Untitled

a guest
May 27th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.28 KB | None | 0 0
  1. using System;
  2.  
  3. namespace MetricConverter
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             double distance = double.Parse(Console.ReadLine());
  10.  
  11.             string metric = Console.ReadLine();
  12.             string toMetric = Console.ReadLine();
  13.  
  14.             double fromInMeters = 0;
  15.  
  16.             if (metric == "m")
  17.             {
  18.                 fromInMeters = distance;
  19.             }
  20.             else if (metric == "mm")
  21.             {
  22.                 fromInMeters = distance / 1000;
  23.             }
  24.             else if (metric == "cm")
  25.             {
  26.                 fromInMeters = distance / 100;
  27.             }
  28.             else if (metric == "mi")
  29.             {
  30.                 fromInMeters = distance / 0.000621371192;
  31.             }
  32.             else if (metric == "in")
  33.             {
  34.                 fromInMeters = distance / 39.3700787;
  35.             }
  36.             else if (metric == "km")
  37.             {
  38.                 fromInMeters = distance / 0.001;
  39.             }
  40.             else if (metric == "ft")
  41.             {
  42.                 fromInMeters = distance / 3.2808399;
  43.             }
  44.             else if (metric == "yd")
  45.             {
  46.                 fromInMeters = distance / 1.0936133;
  47.             }
  48.  
  49.             double result = 0;
  50.  
  51.             if (toMetric == "m")
  52.             {
  53.                 result = distance;
  54.             }
  55.             else if (toMetric == "mm")
  56.             {
  57.                 result = fromInMeters * 1000;
  58.             }
  59.             else if (toMetric == "cm")
  60.             {
  61.                 result = fromInMeters * 100;
  62.             }
  63.             else if (toMetric == "mi")
  64.             {
  65.                 result = fromInMeters * 0.000621371192;
  66.             }
  67.             else if (toMetric == "in")
  68.             {
  69.                 result = fromInMeters * 39.3700787;
  70.             }
  71.             else if (toMetric == "km")
  72.             {
  73.                 result = fromInMeters * 0.001;
  74.             }
  75.             else if (toMetric == "ft")
  76.             {
  77.                 result = fromInMeters * 3.2808399;
  78.             }
  79.             else if (toMetric == "yd")
  80.             {
  81.                 result = fromInMeters * 1.0936133;
  82.             }
  83.  
  84.             Console.WriteLine($"{result:F8}");
  85.         }
  86.     }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement