Advertisement
EvenGuy

Test.cs

Jan 19th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.07 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 ConsoleApplication26
  8. {
  9.     class Program
  10.     {
  11.         static Boolean isNum(String sNum)
  12.         {
  13.             try
  14.             {
  15.                 int num = Int32.Parse(sNum);
  16.             }
  17.             catch
  18.             {
  19.                 return false;
  20.             }
  21.  
  22.             return true;
  23.         }
  24.  
  25.         static int getNum(String Msg)
  26.         {
  27.             String Str;
  28.             do
  29.             {
  30.                 Console.Write(Msg);
  31.                 Str = Console.ReadLine();
  32.                 if (!isNum(Str))
  33.                     Console.WriteLine("Неверный формат");
  34.             } while (!isNum(Str));
  35.  
  36.             return Convert.ToInt32(Str);
  37.         }
  38.  
  39.         static void Main(string[] args)
  40.         {
  41.             int a = getNum("Введите A: ");
  42.             int b = getNum("Введите B: ");
  43.  
  44.             Console.WriteLine("A + B = "+(a+b));
  45.             Console.ReadLine();
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement