Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace WhileEnterExit
- {
- class Program
- {
- static void Main(string[] args)
- {
- int initialValue = 0;
- int finalValue = 10;
- bool isOpen = true;
- bool isNumber = false;
- string userInput;
- int currentNumber;
- Random random = new Random();
- Console.WriteLine($"Угадайте число от {initialValue} до {finalValue}. Напишите \"exit\" для выхода.");
- while (isOpen)
- {
- currentNumber = random.Next(0, 11);
- Console.Write("Ваше число: ");
- userInput = Console.ReadLine();
- isNumber = Int32.TryParse(userInput, out int value);
- if (isNumber && value >= initialValue && value <= finalValue)
- {
- if (value == currentNumber)
- {
- Console.WriteLine("Поздравляю, вы угадали!");
- }
- else
- {
- Console.WriteLine($"Вы не угадали! Загаданное число: {currentNumber}");
- }
- }
- else if (userInput == "exit")
- {
- isOpen = false;
- }
- else
- {
- Console.WriteLine($"Некорректный ввод. Введите число от {initialValue} до {finalValue}. Напишите \"exit\" для выхода.");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement