Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- namespace metricsConverter
- {
- class Program
- {
- static void Main(string[] args)
- {
- double value = double.Parse( Console.ReadLine() );
- string startMetric = Console.ReadLine().ToLower();
- string finalMetric = Console.ReadLine().ToLower();
- //end of reading data;
- Dictionary<string, double> metrics = new Dictionary<string, double>();
- metrics.Add("m", 1);
- metrics.Add("mm", 0.001);
- metrics.Add("cm", 0.01);
- metrics.Add("mi", 1609.344);
- metrics.Add("in", 0.0254);
- metrics.Add("km", 1000);
- metrics.Add("ft", 0.3048);
- metrics.Add("yd", 0.9144);
- //end of adding metrics
- double startValue = 0;
- double finalValue = 0;
- //creater value for final calculations
- foreach (KeyValuePair<string, double> entry in metrics)
- {
- //keys and values from metrics dictionary are stored in entry
- if(startMetric == entry.Key)
- {
- startValue = entry.Value;
- }
- if(finalMetric == entry.Key)
- {
- finalValue = entry.Value;
- }
- }
- double result = (value * startValue) /
- Console.WriteLine("{0:f8}", result);
- //format result to 8-th digit
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement