Anonim_999

Untitled

Mar 6th, 2021 (edited)
666
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.95 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp1
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int numberUser = CountNumber();
  10.             Console.WriteLine($"Возвращенное число: {numberUser}");
  11.         }
  12.  
  13.         private static int CountNumber()
  14.         {
  15.             int number = 0;
  16.             bool isSuccess = false;
  17.  
  18.             while (!isSuccess)
  19.             {
  20.                 Console.Write("Введите число: ");
  21.                 string userInput = Console.ReadLine();
  22.                 bool success = Int32.TryParse(userInput, out number);
  23.  
  24.                 if (!success)
  25.                 {
  26.                     Console.WriteLine($"Попытка преобразования '{userInput}' неудачна.");
  27.                 }
  28.                 else
  29.                 {
  30.                     isSuccess = true;
  31.                 }
  32.                
  33.             }
  34.             return number;
  35.         }
  36.     }
  37. }
Add Comment
Please, Sign In to add comment