viraco4a

MetricConverter_short

Jan 26th, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 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 _08_MetricConverter
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. double inputNumber = double.Parse(Console.ReadLine());
  14. string inputMetric = Console.ReadLine().ToLower();
  15. string outputMetric = Console.ReadLine().ToLower();
  16. Dictionary<string, double> MetricDict = new Dictionary<string, double>()
  17. {
  18. { "m", 1 }, { "mm", 1000 }, { "cm", 100 }, { "mi", 0.000621371192 }, { "in", 39.3700787 },
  19. { "km", 0.001 }, { "ft", 3.2808399 }, { "yd", 1.0936133 },
  20. };
  21. double result = 0.0;
  22. foreach (KeyValuePair<string, double> metricPair in MetricDict)
  23. {
  24. KeyValuePair<string, double> kvp = metricPair;
  25. if (inputMetric == kvp.Key)
  26. {
  27. result = inputNumber / kvp.Value;
  28. }
  29. }
  30.  
  31. foreach (KeyValuePair<string, double> metricPair in MetricDict)
  32. {
  33. KeyValuePair<string, double> kvp = metricPair;
  34. if (outputMetric == kvp.Key)
  35. {
  36. result *= kvp.Value;
  37. }
  38. }
  39.  
  40. Console.WriteLine($"{result:f8}");
  41. }
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment