OldBeliver

Function_03ver02

Mar 26th, 2021 (edited)
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.19 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ReadInt_02
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             bool doExit = false;
  14.             bool result = false;
  15.             int number;
  16.  
  17.             while (doExit == false)
  18.             {                
  19.                 if (CheckNumber(out number))
  20.                 {  
  21.                     Console.WriteLine($"Вы ввели число {number}");
  22.                     Console.ReadKey();
  23.                     doExit = true;
  24.                 }
  25.                 else
  26.                 {
  27.                     Console.Clear();
  28.                     Console.WriteLine("Это не целое число");
  29.                 }  
  30.             }
  31.         }
  32.  
  33.         static bool CheckNumber(out int number)
  34.         {
  35.             string userInput;
  36.             bool result;            
  37.  
  38.             Console.Write($"Введите любое целое число: ");
  39.             userInput = Console.ReadLine();
  40.             result = int.TryParse(userInput, out number);
  41.            
  42.             return result;
  43.         }
  44.     }
  45. }
  46.  
Add Comment
Please, Sign In to add comment