Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _08_MetricConverter
- {
- class Program
- {
- static void Main(string[] args)
- {
- double inputNumber = double.Parse(Console.ReadLine());
- string inputMetric = Console.ReadLine().ToLower();
- string outputMetric = Console.ReadLine().ToLower();
- Dictionary<string, double> MetricDict = new Dictionary<string, double>()
- {
- { "m", 1 }, { "mm", 1000 }, { "cm", 100 }, { "mi", 0.000621371192 }, { "in", 39.3700787 },
- { "km", 0.001 }, { "ft", 3.2808399 }, { "yd", 1.0936133 },
- };
- double result = 0.0;
- foreach (KeyValuePair<string, double> metricPair in MetricDict)
- {
- KeyValuePair<string, double> kvp = metricPair;
- if (inputMetric == kvp.Key)
- {
- result = inputNumber / kvp.Value;
- }
- }
- foreach (KeyValuePair<string, double> metricPair in MetricDict)
- {
- KeyValuePair<string, double> kvp = metricPair;
- if (outputMetric == kvp.Key)
- {
- result *= kvp.Value;
- }
- }
- Console.WriteLine($"{result:f8}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment