Advertisement
simonradev

CurrencyConverter

May 12th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.96 KB | None | 0 0
  1. namespace _1000DaysAfterBirth
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.     using System.Globalization;
  6.     using System.Linq;
  7.     using System.Text;
  8.     using System.Threading.Tasks;
  9.    
  10.     public class Program
  11.     {
  12.         public static void Main()
  13.         {
  14.             double amountToConvert = double.Parse(Console.ReadLine());
  15.             string fromCurrency = Console.ReadLine();
  16.             string toCurrency = Console.ReadLine();
  17.  
  18.             string bgnString = "BGN";
  19.             string usdString = "USD";
  20.             string eurString = "EUR";
  21.             string gbpString = "GBP";
  22.  
  23.             double bgnValue = 1.0;
  24.             double usdValue = 1.79549;
  25.             double eurValue = 1.95583;
  26.             double gbpValue = 2.53405;
  27.  
  28.             double fromValue = 0.0;
  29.             double toValue = 0.0;
  30.             if (fromCurrency == bgnString)
  31.             {
  32.                 fromValue = bgnValue;
  33.  
  34.                 if (toCurrency == usdString)
  35.                 {
  36.                     toValue = usdValue;
  37.                 }
  38.                 else if (toCurrency == eurString)
  39.                 {
  40.                     toValue = eurValue;
  41.                 }
  42.                 else if (toCurrency == gbpString)
  43.                 {
  44.                     toValue = gbpValue;
  45.                 }
  46.             }
  47.             else if (fromCurrency == usdString)
  48.             {
  49.                 fromValue = usdValue;
  50.  
  51.                 if (toCurrency == bgnString)
  52.                 {
  53.                     toValue = bgnValue;
  54.                 }
  55.                 else if (toCurrency == eurString)
  56.                 {
  57.                     toValue = eurValue;
  58.                 }
  59.                 else if (toCurrency == gbpString)
  60.                 {
  61.                     toValue = gbpValue;
  62.                 }
  63.             }
  64.             else if (fromCurrency == eurString)
  65.             {
  66.                 fromValue = eurValue;
  67.  
  68.                 if (toCurrency == bgnString)
  69.                 {
  70.                     toValue = bgnValue;
  71.                 }
  72.                 else if (toCurrency == usdString)
  73.                 {
  74.                     toValue = usdValue;
  75.                 }
  76.                 else if (toCurrency == gbpString)
  77.                 {
  78.                     toValue = gbpValue;
  79.                 }
  80.             }
  81.             else if (fromCurrency == gbpString)
  82.             {
  83.                 fromValue = gbpValue;
  84.  
  85.                 if (toCurrency == bgnString)
  86.                 {
  87.                     toValue = bgnValue;
  88.                 }
  89.                 else if (toCurrency == usdString)
  90.                 {
  91.                     toValue = usdValue;
  92.                 }
  93.                 else if (toCurrency == eurString)
  94.                 {
  95.                     toValue = eurValue;
  96.                 }
  97.             }
  98.  
  99.             double result = (fromValue / toValue) * amountToConvert;
  100.  
  101.             Console.WriteLine($"{result:f2} {toCurrency}");
  102.         }
  103.     }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement