Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace checknumber
- {
- class Program
- {
- static void Main(string[] args)
- {
- int result = CheckNumber();
- Console.WriteLine("Вы ввели число: " + result);
- }
- static int CheckNumber()
- {
- string userInput;
- int result = int.MinValue;
- bool numberEntered = false;
- while (!numberEntered)
- {
- Console.Write("Введите число: ");
- userInput = Console.ReadLine();
- if (int.TryParse(userInput, out result))
- {
- numberEntered = true;
- }
- else
- {
- WriteError();
- }
- }
- return result;
- }
- static void WriteError()
- {
- ConsoleColor defaultColor = Console.ForegroundColor;
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("Это не число!");
- Console.ForegroundColor = defaultColor;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement