SimeonSheytanov

Currency Conventer - 2 Arrays

Jan 31st, 2016
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.23 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 TeamsOrganizer
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string[] currencyName = new string[] {"USD", "BGN", "GBP", "EUR"};
  14.             decimal[] currencyValue = new decimal[] { 1.7435m, 1m, 2.6435m, 1.954m};
  15.  
  16.             decimal money = decimal.Parse(Console.ReadLine());
  17.             string currency = Console.ReadLine();
  18.             string wantedCurrency = Console.ReadLine();
  19.             int index = -1;
  20.             int indexWantedCurrency = -1;
  21.  
  22.             for (int i = 0; i < currencyName.Length; i++)
  23.             {
  24.                 if (currencyName[i] == currency)
  25.                 {
  26.                     index = i;
  27.                    
  28.                 }
  29.                 if (currencyName[i] == wantedCurrency)
  30.                 {
  31.                     indexWantedCurrency = i;
  32.                     break;
  33.                 }
  34.             }
  35.  
  36.             decimal moneyInLeva = money * currencyValue[index];
  37.             decimal moneyResult = moneyInLeva / currencyValue[indexWantedCurrency];
  38.             Console.WriteLine(moneyResult);
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment