Advertisement
SomeBody_Aplle

Untitled

Mar 25th, 2021
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.53 KB | None | 0 0
  1. static void Action(uint action, ref int balance, int refill = 0, int cut = 0)
  2.         {
  3.             switch (action)
  4.             {
  5.                 case 1:
  6.                     Console.WriteLine();
  7.                     Console.WriteLine($"Ваш баланс = {balance} руб.");
  8.                     Console.ReadLine();
  9.                     break;
  10.  
  11.                 case 2:
  12.                     Console.WriteLine();
  13.                     Console.WriteLine("На какую сумму хотите пополнить баланс?");
  14.                     Console.Write("Введите сумму: ");
  15.                     refill = int.Parse(Console.ReadLine());
  16.                     if (refill <= 0)
  17.                     {
  18.                         Console.WriteLine("Вы ввели некорректное значение!");
  19.                         Console.ReadLine();
  20.                         break;
  21.                     }
  22.                     else
  23.                     {
  24.                         balance += refill;
  25.                         break;
  26.                     }
  27.                    
  28.                 case 3:
  29.                     Console.WriteLine();
  30.                     Console.WriteLine("Какую сумму хотите снять с баланса?");
  31.                     Console.Write("Введите сумму: ");
  32.                     cut = int.Parse(Console.ReadLine());
  33.                     if (cut <= 0)
  34.                     {
  35.                         Console.WriteLine("Вы ввели некорректное значение!");
  36.                         Console.ReadLine();
  37.                         break;
  38.                     }
  39.                     if (balance >= cut)
  40.                     {
  41.                         balance -= cut;
  42.                     }
  43.                     else
  44.                     {
  45.                         Console.WriteLine("На балансе недостаточно средств!");
  46.                         Console.ReadLine();
  47.                     }
  48.                     break;
  49.  
  50.                 default:
  51.                     Console.WriteLine();
  52.                     Console.WriteLine("Вы ввели некорректное значение!");
  53.                     break;
  54.             }
  55.         }
  56.        
  57.         static void Massage()
  58.         {
  59.             Console.WriteLine("\t========Bank========");
  60.             Console.WriteLine();
  61.             Console.WriteLine("\t Выберите действие:");
  62.             Console.WriteLine("1. Узнать баланс");
  63.             Console.WriteLine("2. Пополнить баланс");
  64.             Console.WriteLine("3. Снять наличные");
  65.             Console.WriteLine("4. Выход из приложения");
  66.             Console.WriteLine();
  67.         }
  68.  
  69.         static void Main(string[] args)
  70.         {
  71.             int balance = 0;
  72.             uint action = 0;
  73.            
  74.             while (action != 4)
  75.             {
  76.                 Massage();
  77.                 try
  78.                 {
  79.                     action = uint.Parse(Console.ReadLine());
  80.                 }
  81.                 catch (Exception)
  82.                 {
  83.                     Console.WriteLine("Вы ввели недопустимое значение!");
  84.                     Console.ReadLine();
  85.                 }
  86.                 Action(action, ref balance);
  87.                 Console.Clear();
  88.             }
  89.             Console.WriteLine("Для выхода из программы нажмите любую клавишу...");
  90.             Console.ReadKey();
  91.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement