Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ConsoleApp3
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- const string CommandSaveMyName = "1";
- const string CommandPrintMyName = "2";
- const string CommandPrintRandomNumber = "3";
- const string CommandClearConsol = "4";
- const string CommandExit = "5";
- Random random = new Random();
- string userComand = "";
- string stopComand = "exit";
- string userName = "";
- int randomNumber;
- while (userComand != stopComand)
- {
- Console.Write($"Меню:\n1) Записать мое имя: {CommandSaveMyName}\n2) Вывести мое имя: {CommandPrintMyName}\n3) Вывести рандомное число: {CommandPrintRandomNumber}\n4) Очистить консоль: {CommandClearConsol}\n5) Выход: {CommandExit}\n\nВведите номер команды: ");
- userComand = Console.ReadLine();
- switch (userComand)
- {
- case CommandSaveMyName:
- Console.Write("Введите ваше имя: ");
- userName = Console.ReadLine();
- break;
- case CommandPrintMyName:
- if (userName == "")
- {
- Console.WriteLine("Вы еще не сохранили ваше имя!\n\n");
- } else
- {
- Console.WriteLine($"Ваше имя: {userName}.\n\n");
- }
- break;
- case CommandPrintRandomNumber:
- randomNumber = random.Next(0,101);
- Console.Write($"Ваше рандомное число: {randomNumber}.\n\n");
- break;
- case CommandClearConsol:
- Console.Clear();
- break;
- case CommandExit:
- userComand = stopComand;
- break;
- default:
- Console.WriteLine("Нет такой команды. Убедитесь в правельности ввода.\n\n");
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement