Advertisement
Dianov

Conditional Statements - Exercise (04. Metric Converter)

Oct 16th, 2020
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.63 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 MetricConverter
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             double length = double.Parse(Console.ReadLine());
  14.             string string1 = Console.ReadLine();
  15.             string string2 = Console.ReadLine();
  16.  
  17.             if (string1 == "mm")
  18.             {
  19.                 if (string2 == "cm")
  20.                 {
  21.                     length = length / 10;
  22.                     Console.WriteLine("{0:F3}", length);
  23.                 }
  24.                 if (string2 == "m")
  25.                 {
  26.                     length = length / 1000;
  27.                     Console.WriteLine("{0:F3}", length);
  28.                 }
  29.             }
  30.             if (string1 == "cm")
  31.             {
  32.                 if (string2 == "mm")
  33.                 {
  34.                     length = length * 10;
  35.                     Console.WriteLine("{0:F3}", length);
  36.                 }
  37.                 if (string2 == "m")
  38.                 {
  39.                     length = length / 100;
  40.                     Console.WriteLine("{0:F3}", length);
  41.                 }
  42.             }
  43.             if (string1 == "m")
  44.             {
  45.                 if (string2 == "mm")
  46.                 {
  47.                     length = length * 1000;
  48.                     Console.WriteLine("{0:F3}", length);
  49.                 }
  50.                 if (string2 == "cm")
  51.                 {
  52.                     length = length * 100;
  53.                     Console.WriteLine("{0:F3}", length);
  54.                 }
  55.             }
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement