Advertisement
avramovivan

MetricConverter

Oct 21st, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 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 _8.MetricConverter
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. double distance = double.Parse(Console.ReadLine());
  14. string currentUnit = Console.ReadLine();
  15. string wantedUnit = Console.ReadLine();
  16.  
  17. double convertedDistance = distance;
  18.  
  19. if (currentUnit == "mm")
  20. {
  21. convertedDistance = distance / 1000.0;
  22. }
  23. else if (currentUnit == "cm")
  24. {
  25. convertedDistance = distance / 100.0;
  26. }
  27. else if (currentUnit == "mi")
  28. {
  29. convertedDistance = distance / 0.000621371192;
  30. }
  31. else if (currentUnit == "in")
  32. {
  33. convertedDistance = distance / 39.3700787;
  34. }
  35. else if (currentUnit == "km")
  36. {
  37. convertedDistance = distance / 0.001;
  38. }
  39. else if (currentUnit == "ft")
  40. {
  41. convertedDistance = distance / 3.2808399;
  42. }
  43. else if (currentUnit == "yd")
  44. {
  45. convertedDistance = distance / 1.0936133;
  46. }
  47.  
  48.  
  49. if (wantedUnit == "mm")
  50. {
  51. convertedDistance = convertedDistance * 1000.0;
  52. }
  53. else if (wantedUnit == "cm")
  54. {
  55. convertedDistance = convertedDistance * 100.0;
  56. }
  57. else if (wantedUnit == "mi")
  58. {
  59. convertedDistance = convertedDistance * 0.000621371192;
  60. }
  61. else if (wantedUnit == "in")
  62. {
  63. convertedDistance = convertedDistance * 39.3700787;
  64. }
  65. else if (wantedUnit == "km")
  66. {
  67. convertedDistance = convertedDistance * 0.001;
  68. }
  69. else if (wantedUnit == "ft")
  70. {
  71. convertedDistance = convertedDistance * 3.2808399;
  72. }
  73. else if (wantedUnit == "yd")
  74. {
  75. convertedDistance = convertedDistance * 1.0936133;
  76. }
  77.  
  78. Console.WriteLine($"{convertedDistance} {wantedUnit}");
  79.  
  80.  
  81. }
  82. }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement