Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ConsoleApp1
- {
- class Program
- {
- static void Main(string[] args)
- {
- int numberUser = CountNumber();
- Console.WriteLine($"Возвращенное число: {numberUser}");
- }
- private static int CountNumber()
- {
- int number = 0;
- bool isSuccess = false;
- while (!isSuccess)
- {
- Console.Write("Введите число: ");
- string userInput = Console.ReadLine();
- bool success = Int32.TryParse(userInput, out number);
- if (!success)
- {
- Console.WriteLine($"Попытка преобразования '{userInput}' неудачна.");
- }
- else
- {
- isSuccess = true;
- }
- }
- return number;
- }
- }
- }
Add Comment
Please, Sign In to add comment