Advertisement
Anonim_999

Untitled

Mar 6th, 2021
1,134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.85 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;
  16.             bool isContinue = true;
  17.  
  18.             while (isContinue)
  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.             }
  29.             return number;
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement