Advertisement
Guest User

04. Metric Converter - Solution 2

a guest
Oct 21st, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.26 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 num = double.Parse(Console.ReadLine());
  10.             string input = Console.ReadLine();
  11.             string output = Console.ReadLine();
  12.  
  13.             double result = 0;
  14.  
  15.             if(input == "m")
  16.             {
  17.                 if (output == "cm")
  18.                 {
  19.                     result = num * 100;
  20.                 }
  21.                 else if (output == "mm")
  22.                 {
  23.                     result = num * 1000;
  24.                 }
  25.             }
  26.             else if(input == "cm")
  27.             {
  28.                 if (output == "m")
  29.                 {
  30.                     result = num / 100;
  31.                 }
  32.                 else if (output == "mm")
  33.                 {
  34.                     result = num * 10;
  35.                 }
  36.             }
  37.             else if(input == "mm")
  38.             {
  39.                 if (output == "cm")
  40.                 {
  41.                     result = num / 10;
  42.                 }
  43.                 else if (output == "m")
  44.                 {
  45.                     result = num / 1000;
  46.                 }
  47.             }
  48.  
  49.  
  50.             Console.WriteLine($"{result:f3}");
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement