Advertisement
TodorovP

Metric_Converter

Jan 21st, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.19 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 Metric_Converter
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {            
  13.             var metricValue = double.Parse(Console.ReadLine());            
  14.             var metricInName = Console.ReadLine();            
  15.             var metricOutName = Console.ReadLine();
  16.  
  17.             byte indexIn = 0;
  18.             byte indexOut = 0;
  19.             string[] metricName = { "m", "mm", "cm", "mi",
  20.                                     "in", "km", "ft", "yd" };
  21.             double[] metricRate = { 1d,    1000d,       100d,    0.000621371192d,
  22.                                      39.3700787d, 0.001d, 3.2808399d, 1.0936133d};
  23.  
  24.             for (byte i = 0; i < metricName.Length; i++)
  25.             {
  26.                 if (metricInName == metricName[i])  indexIn = i;
  27.                 if (metricOutName == metricName[i]) indexOut = i;
  28.             }          
  29.            
  30.             double metricOut = metricValue * metricRate[indexOut] /
  31.                 metricRate[indexIn];
  32.  
  33.             Console.WriteLine($"{metricOut:f8}");
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement