Advertisement
junniorrkaa

Консольное меню

Aug 20th, 2024 (edited)
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.04 KB | Source Code | 0 0
  1. using System;
  2.  
  3. namespace CSLight
  4. {
  5.     internal class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             const string CommandShowText = "1";
  10.             const string CommandClearConsole = "2";
  11.             const string CommandExit = "3";
  12.             const string CommandShowRandomNumber = "4";
  13.  
  14.             bool isWork = true;
  15.             string userInput;
  16.             Random random = new Random();
  17.             int largerNumber = 100;
  18.             int smallerNumber = 0;
  19.             string firstText = "1";
  20.             string secondText = "2";
  21.  
  22.             while (isWork)
  23.             {
  24.                 Console.WriteLine($"{CommandShowText} - Показать текст");
  25.                 Console.WriteLine($"{CommandClearConsole} - Очистить консоль");
  26.                 Console.WriteLine($"{CommandExit} - Выход");
  27.                 Console.WriteLine($"{CommandShowRandomNumber} - Показать случайное число");
  28.                 Console.WriteLine();
  29.  
  30.                 userInput = Console.ReadLine();
  31.  
  32.  
  33.                 switch (userInput)
  34.                 {
  35.                     case CommandShowText:
  36.                         Console.WriteLine();
  37.                         Console.WriteLine($"Какой текст вам показать, {firstText} или {secondText}?");
  38.                         Console.WriteLine();
  39.                         userInput = Console.ReadLine();
  40.  
  41.                         if (userInput == firstText)
  42.                         {
  43.                             Console.WriteLine();
  44.                             Console.WriteLine("Плата за индивидуальность — одиночество.");
  45.                             Console.WriteLine();
  46.                         }
  47.                         else if (userInput == secondText)
  48.                         {
  49.                             Console.WriteLine();
  50.                             Console.WriteLine("Берегите в себе человека.");
  51.                             Console.WriteLine();
  52.                         }
  53.                         break;
  54.  
  55.                     case CommandClearConsole:
  56.                         Console.Clear();
  57.                         break;
  58.  
  59.                     case CommandExit:
  60.                         isWork = false;
  61.                         Console.WriteLine();
  62.                         Console.WriteLine("Программа завершена");
  63.                         Console.WriteLine();
  64.                         break;
  65.  
  66.                     case CommandShowRandomNumber:
  67.                         Console.WriteLine();
  68.                         int number = random.Next(smallerNumber, largerNumber);
  69.                         Console.WriteLine(number);
  70.                         Console.WriteLine();
  71.                         break;
  72.  
  73.                     default:
  74.                         Console.WriteLine("Такой команды нет.");
  75.                         break;
  76.                 }
  77.             }
  78.  
  79.             Console.ReadKey();
  80.  
  81.         }  
  82.     }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement