Advertisement
rukvir

HW 2_6_2

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