Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace ConvectorCurrency
- {
- class Program
- {
- static void Main(string[] args)
- {
- const string CommandChangeRubToUsd = "1";
- const string CommandChangeRubToEuro = "2";
- const string CommandChangeUsdToRub = "3";
- const string CommandChangeUsdЕoEuro = "4";
- const string CommandChangeEuroToRub = "5";
- const string CommandChangeEuroToUsd = "6";
- const string CommandExit = "7";
- int minValueInAccount = 0;
- int maxValueInAccount = 100;
- double accountInRubles;
- double accountInDollars;
- double accountInEuros;
- double dollarToRubleRatio = 89.80;
- double euroToRubleRatio = 97.50;
- double dollarToEuroRatio = 0.92;
- double rubToDollarRatio = 1 / dollarToRubleRatio;
- double rubToEuroRatio = 1 / euroToRubleRatio;
- double euroToDollarRatio = 1 / dollarToEuroRatio;
- bool isWorking = true;
- Random random = new Random();
- accountInDollars = random.Next(minValueInAccount, maxValueInAccount);
- accountInRubles = random.Next(minValueInAccount, maxValueInAccount);
- accountInEuros = random.Next(minValueInAccount, maxValueInAccount);
- while (isWorking)
- {
- Console.WriteLine($"На Вашем счете:\n{accountInDollars} - долларов\n" +
- $"{accountInEuros} - евро\n{accountInRubles} - рублейn\n\n");
- Console.WriteLine($"Для обмена рублей на доллары ведите - {CommandChangeRubToUsd}\n" +
- $"Для обмена рублей на евро введите - {CommandChangeRubToEuro}\n" +
- $"Для обмена доллара на рубли введите - {CommandChangeUsdToRub}\n" +
- $"Для обмена доллара на евро введите - {CommandChangeUsdЕoEuro}\n" +
- $"Для обмена евро на рубли введите - {CommandChangeEuroToRub}\n" +
- $"Для обмена евро на доллары введите - {CommandChangeEuroToUsd}\n" +
- $"Для выхода нажмите - {CommandExit}");
- string userInput = Console.ReadLine();
- switch (userInput)
- {
- case CommandChangeRubToUsd:
- ConvertCurrency(rubToDollarRatio, ref accountInRubles, ref accountInDollars);
- break;
- case CommandChangeRubToEuro:
- ConvertCurrency(rubToEuroRatio, ref accountInRubles, ref accountInEuros);
- break;
- case CommandChangeUsdToRub:
- ConvertCurrency(dollarToRubleRatio, ref accountInDollars, ref accountInRubles);
- break;
- case CommandChangeUsdЕoEuro:
- ConvertCurrency(dollarToEuroRatio, ref accountInDollars, ref accountInEuros);
- break;
- case CommandChangeEuroToRub:
- ConvertCurrency(euroToRubleRatio, ref accountInEuros, ref accountInRubles);
- break;
- case CommandChangeEuroToUsd:
- ConvertCurrency(euroToDollarRatio, ref accountInEuros, ref accountInDollars);
- break;
- case CommandExit:
- Console.WriteLine("Вы вышли из программы.");
- isWorking = false;
- Console.ReadKey();
- break;
- }
- Console.Write("Нажмите любую клавишу");
- Console.ReadKey();
- Console.Clear();
- }
- }
- static void ConvertCurrency(double coefficient, ref double moneyToAccountExchange, ref double moneyToAccountPurchased)
- {
- Console.WriteLine("Введите сколько денег хотите обменять: ");
- bool isNumber = double.TryParse(Console.ReadLine(), out double moneyValue);
- if (moneyValue > moneyToAccountExchange)
- {
- Console.WriteLine("У вас недостаточно средств.");
- return;
- }
- if (isNumber == true)
- {
- moneyToAccountPurchased += Math.Round(moneyValue * coefficient, 2);
- moneyToAccountExchange -= Math.Round(moneyValue, 2);
- }
- else
- {
- Console.WriteLine("Необходимо ввести число. Попробуйте еще раз.");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement