Advertisement
rukvir

HW 2_6

Feb 10th, 2025
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 10.18 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3.  
  4. namespace HW_2025
  5. {
  6.     internal class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             //команды обмена
  11.             const string CommandRubToUsd = "RUB/USD";
  12.             const string CommandRubToEur = "RUB/EUR";
  13.             const string CommandUsdToRub = "USD/RUB";
  14.             const string CommandUsdToEur = "USD/EUR";
  15.             const string CommandEurToRub = "EUR/RUB";
  16.             const string CommandEurToUsd = "EUR/USD";
  17.             //меню
  18.             const string CommandBalance = "/Balance";
  19.             const string CommandClearConsole = "/ClearConsole";
  20.             const string CommandExit = "/Exit";
  21.             const string CommandHelp = "/Help";
  22.             int secondsToMilliseconds = 1000;
  23.             // Курсы валют
  24.             double usdToEurRate = 0.85;
  25.             double usdToRubRate = 75.0;
  26.             double eurToUsdRate = 1.18;
  27.             double eurToRubRate = 88.0;
  28.             double rubToUsdRate = 0.0104;
  29.             double rubToEurRate = 0.011;
  30.             // Баланс
  31.             double balanceRub = 10000;
  32.             double balanceUsd = 100;
  33.             double balanceEur = 50;
  34.            
  35.             double userAmountСurrency;
  36.  
  37.             bool isWork = true;
  38.             string userInput;
  39.  
  40.             Console.WriteLine("Бот Сonverter к Вашем уcлугам.\n" +
  41.                 $"Узнайте свой баланс {CommandBalance}\n" +
  42.                 $"Узнать возможности можно через {CommandHelp}\n");
  43.  
  44.             while (isWork)
  45.             {
  46.                 userInput = Console.ReadLine();
  47.  
  48.                 switch (userInput)
  49.                 {
  50.                     case CommandClearConsole:
  51.                         Console.WriteLine("Консоль будет очищена через 3 секунды\n");
  52.                         System.Threading.Thread.Sleep(secondsToMilliseconds * 3);
  53.                         Console.Clear();
  54.                         break;
  55.                     case CommandHelp:
  56.                         Console.WriteLine($"Команды чтобы обменять:\n" +
  57.                             $"{CommandRubToUsd}\n" +
  58.                             $"{CommandRubToEur}\n" +
  59.                             $"{CommandUsdToRub}\n" +
  60.                             $"{CommandUsdToEur}\n" +
  61.                             $"{CommandEurToRub}\n" +
  62.                             $"{CommandEurToUsd}\n");
  63.                         break;
  64.                     case CommandBalance:
  65.                         Console.WriteLine($"Ваш баланс:\n" +
  66.                             $"############\n" +
  67.                             $"RUB: {balanceRub}\n" +
  68.                             $"USD: {balanceUsd}\n" +
  69.                             $"EUR: {balanceEur}\n" +
  70.                             $"############");
  71.                         break;
  72.                     case CommandExit:
  73.                         isWork = false;
  74.                         Console.WriteLine("Программа закрыта");
  75.                         break;
  76.  
  77.                     case CommandRubToUsd: // Rub -> Usd
  78.                         Console.Write("Введите сумму для конвертации: ");
  79.                         userAmountСurrency = Convert.ToInt32(Console.ReadLine());
  80.                         // Проверка на отрицательные значения
  81.                         if (userAmountСurrency < 0)
  82.                         {
  83.                             Console.WriteLine("Ошибка: Сумма не может быть отрицательной.");
  84.                             continue;
  85.                         }
  86.                         else if(userAmountСurrency > balanceRub)
  87.                         {
  88.                             Console.WriteLine($"Ошибка: Недостаточно средств на балансе. Ваш счет = {balanceRub}\"");
  89.                         }
  90.                         else
  91.                         {
  92.                             balanceRub -= userAmountСurrency;
  93.                             balanceUsd += userAmountСurrency * rubToUsdRate;
  94.                             Console.WriteLine($"Произведен обмен {CommandRubToUsd}");
  95.                         }
  96.                         break;
  97.                     case CommandRubToEur: // Rub -> Eur
  98.                         Console.Write("Введите сумму для конвертации: ");
  99.                         userAmountСurrency = Convert.ToInt32(Console.ReadLine());
  100.                         if (userAmountСurrency < 0)
  101.                         {
  102.                             Console.WriteLine("Ошибка: Сумма не может быть отрицательной.");
  103.                             continue;
  104.                         }
  105.                         else if (userAmountСurrency > balanceRub)
  106.                         {
  107.                             Console.WriteLine($"Ошибка: Недостаточно средств на балансе. Ваш счет = {balanceRub}");
  108.                         }
  109.                         else
  110.                         {
  111.                             balanceRub -= userAmountСurrency;
  112.                             balanceEur += userAmountСurrency * rubToEurRate;
  113.                             Console.WriteLine($"Произведен обмен {CommandRubToEur}");
  114.                         }
  115.                         break;
  116.                     case CommandUsdToRub: // Usd -> Rub
  117.                         Console.Write("Введите сумму для конвертации: ");
  118.                         userAmountСurrency = Convert.ToInt32(Console.ReadLine());
  119.                         if (userAmountСurrency < 0)
  120.                         {
  121.                             Console.WriteLine("Ошибка: Сумма не может быть отрицательной.");
  122.                             continue;
  123.                         }
  124.                         else if (userAmountСurrency > balanceUsd)
  125.                         {
  126.                             Console.WriteLine($"Ошибка: Недостаточно средств на балансе. Ваш счет = {balanceUsd}");
  127.                         }
  128.                         else
  129.                         {
  130.                             balanceUsd -= userAmountСurrency;
  131.                             balanceRub += userAmountСurrency * usdToRubRate;
  132.                             Console.WriteLine($"Произведен обмен {CommandUsdToRub}");
  133.                         }
  134.                         break;
  135.                     case CommandUsdToEur: // Usd -> Eur
  136.                         Console.Write("Введите сумму для конвертации: ");
  137.                         userAmountСurrency = Convert.ToInt32(Console.ReadLine());
  138.                         if (userAmountСurrency < 0)
  139.                         {
  140.                             Console.WriteLine("Ошибка: Сумма не может быть отрицательной.");
  141.                             continue;
  142.                         }
  143.                         else if (userAmountСurrency > balanceUsd)
  144.                         {
  145.                             Console.WriteLine($"Ошибка: Недостаточно средств на балансе. Ваш счет = {balanceUsd}");
  146.                         }
  147.                         else
  148.                         {
  149.                             balanceUsd -= userAmountСurrency;
  150.                             balanceEur += userAmountСurrency * usdToEurRate;
  151.                             Console.WriteLine($"Произведен обмен {CommandUsdToEur}");
  152.                         }
  153.                         break;
  154.                     case CommandEurToRub: // Eur -> Rub
  155.                         Console.Write("Введите сумму для конвертации: ");
  156.                         userAmountСurrency = Convert.ToInt32(Console.ReadLine());
  157.                         if (userAmountСurrency < 0)
  158.                         {
  159.                             Console.WriteLine("Ошибка: Сумма не может быть отрицательной.");
  160.                             continue;
  161.                         }
  162.                         else if (userAmountСurrency > balanceEur)
  163.                         {
  164.                             Console.WriteLine($"Ошибка: Недостаточно средств на балансе. Ваш счет = {balanceEur}");
  165.                         }
  166.                         else
  167.                         {
  168.                             balanceEur -= userAmountСurrency;
  169.                             balanceRub += userAmountСurrency * eurToRubRate;
  170.                             Console.WriteLine($"Произведен обмен {CommandEurToRub}");
  171.                         }
  172.                         break;
  173.                     case CommandEurToUsd: // Eur -> Usd
  174.                         Console.Write("Введите сумму для конвертации: ");
  175.                         userAmountСurrency = Convert.ToInt32(Console.ReadLine());
  176.                         if (userAmountСurrency < 0)
  177.                         {
  178.                             Console.WriteLine("Ошибка: Сумма не может быть отрицательной.");
  179.                             continue;
  180.                         }
  181.                         else if (userAmountСurrency > balanceEur)
  182.                         {
  183.                             Console.WriteLine($"Ошибка: Недостаточно средств на балансе. Ваш счет = {balanceEur}");
  184.                         }
  185.                         else
  186.                         {
  187.                             balanceEur -= userAmountСurrency;
  188.                             balanceUsd += userAmountСurrency * eurToUsdRate;
  189.                             Console.WriteLine($"Произведен обмен {CommandEurToUsd}");
  190.                         }
  191.                         break;
  192.                     default:
  193.                         Console.WriteLine("Нет такой комманды");
  194.                         break;
  195.                 }
  196.             }
  197.         }
  198.     }
  199. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement