Advertisement
MarinParov

Currency Converter if statements need optimization

Mar 20th, 2019
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.38 KB | None | 0 0
  1. // This is a currency converter that needs optimization.
  2.  
  3. namespace Currency_converter
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. double result = 0;
  10. var money = double.Parse(Console.ReadLine());
  11. var inputCurrency = Console.ReadLine();
  12. var outputCurrency =(Console.ReadLine());
  13.  
  14. if (inputCurrency == "BGN")
  15. {
  16. if (outputCurrency == "EUR")
  17. {
  18. result = money / 1.95583;
  19. }
  20. else if (outputCurrency == "USD")
  21. {
  22. result = money / 1.79549;
  23. }
  24. else if (outputCurrency == "GBP")
  25. {
  26. result = money / 2.53405;
  27. }
  28. }
  29.  
  30. else if (inputCurrency == "USD")
  31. {
  32. if (outputCurrency == "EUR")
  33. {
  34. result = (money * 1.79549) / 1.95583;
  35. }
  36. else if (outputCurrency == "BGN")
  37. {
  38. result = money * 1.79549;
  39. }
  40. else if (outputCurrency == "GBP")
  41. {
  42. result = (money * 1.79549) / 2.53405;
  43. }
  44. }
  45.  
  46. else if (inputCurrency == "EUR")
  47. {
  48. if (outputCurrency == "USD")
  49. {
  50. result = (money * 1.95583) / 1.79549;
  51. }
  52. else if (outputCurrency == "BGN")
  53. {
  54. result = money * 1.95583;
  55. }
  56. else if (outputCurrency == "GBP")
  57. {
  58. result = (money * 1.95583) / 2.53405;
  59. }
  60. }
  61.  
  62. else if (inputCurrency == "GBR")
  63. {
  64. if (outputCurrency == "USD")
  65. {
  66. result = (money * 2.53405) / 1.79549;
  67. }
  68. else if (outputCurrency == "BGN")
  69. {
  70. result = money * 2.53405;
  71. }
  72. else if (outputCurrency == "EUR")
  73. {
  74. result = (money * 2.53405) / 1.95583;
  75. }
  76. }
  77.  
  78. Console.Write($"{result:F2} ");
  79. Console.WriteLine(outputCurrency);
  80. }
  81. }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement