Advertisement
bacco

Конвертор за мерни единици

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