Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace currencyConverter
- {
- class Program
- {
- static void Main(string[] args)
- {
- const string CommandExit = "exit";
- const string CommandConvert = "convert";
- const string UsdToEurRate = "1";
- const string EurToUsdRate = "2";
- const string RurToEurRate = "3";
- const string EurToRurRate = "4";
- const string RurToUsdRate = "5";
- const string UsdToRurRate = "6";
- const string ErrorInsufficient = "Недостаточно средств на счёте";
- const string ErrorRate = "Неверно выбрано направление конвертации";
- const string ErrorCommand = "Неизвестная команда";
- float usdBalance = 100;
- float eurBalance = 100;
- float rurBalance = 1000;
- float usdToEurPrice = 1.08f;
- float eurToUsdPrice = 0.9f;
- float rurToEurPrice = 0.011f;
- float eurToRurPrice = 82.4f;
- float rurToUsdPrice = 0.012f;
- float usdToRurPrice = 76.45f;
- string rate;
- string userInput;
- int sellingValue = 0;
- bool isRunning = true;
- while (isRunning)
- {
- Console.WriteLine($">Текущий баланс:\nUSD > {usdBalance}\nEUR > {eurBalance}\nRUR > {rurBalance}\n");
- Console.WriteLine("Какое действие желаете выполнить?");
- Console.WriteLine($"Конвертация валют - {CommandConvert}, выход - {CommandExit}");
- userInput = Console.ReadLine();
- switch(userInput)
- {
- case CommandConvert:
- Console.WriteLine("Выберите направление обмена: ");
- Console.WriteLine($"{UsdToEurRate} - Доллар в Евро");
- Console.WriteLine($"{EurToUsdRate} - Евро в Доллар");
- Console.WriteLine($"{RurToEurRate} - Рубль в Евро");
- Console.WriteLine($"{EurToRurRate} - Евро в Рубль");
- Console.WriteLine($"{RurToUsdRate} - Рубль в Доллар");
- Console.WriteLine($"{UsdToRurRate} - Доллар в Рубль");
- rate = Console.ReadLine();
- Console.Write("Объём продаваемой валюты: ");
- sellingValue = Convert.ToInt32(Console.ReadLine());
- switch (rate)
- {
- case UsdToEurRate:
- if(usdBalance >= sellingValue)
- {
- usdBalance -= sellingValue;
- eurBalance += sellingValue * usdToEurPrice;
- }
- else
- {
- Console.WriteLine(ErrorInsufficient);
- }
- break;
- case EurToUsdRate:
- if(eurBalance >= sellingValue)
- {
- eurBalance -= sellingValue;
- usdBalance += sellingValue * eurToUsdPrice;
- }
- else
- {
- Console.WriteLine(ErrorInsufficient);
- }
- break;
- case RurToEurRate:
- if (rurBalance >= sellingValue)
- {
- rurBalance -= sellingValue;
- eurBalance += sellingValue * rurToEurPrice;
- }
- else
- {
- Console.WriteLine(ErrorInsufficient);
- }
- break;
- case EurToRurRate:
- if (eurBalance >= sellingValue)
- {
- eurBalance -= sellingValue;
- rurBalance += sellingValue * eurToRurPrice;
- }
- else
- {
- Console.WriteLine(ErrorInsufficient);
- }
- break;
- case RurToUsdRate:
- if (rurBalance >= sellingValue)
- {
- rurBalance -= sellingValue;
- usdBalance += sellingValue * rurToUsdPrice;
- }
- else
- {
- Console.WriteLine(ErrorInsufficient);
- }
- break;
- case UsdToRurRate:
- if (usdBalance >= sellingValue)
- {
- usdBalance -= sellingValue;
- rurBalance += sellingValue * usdToRurPrice;
- }
- else
- {
- Console.WriteLine(ErrorInsufficient);
- }
- break;
- default:
- Console.WriteLine(ErrorRate);
- break;
- }
- break;
- case CommandExit:
- isRunning = false;
- break;
- default:
- Console.WriteLine(ErrorCommand);
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement