Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Task30
- {
- class Program
- {
- static void Main(string[] args)
- {
- string endProgramm = "Программа выполнена успешно и завершена.";
- string convertNumber = "Число: ";
- int number;
- number = GetInt();
- Console.WriteLine(convertNumber + number);
- Console.WriteLine("\n" + endProgramm);
- }
- static int GetInt()
- {
- string errorConversion = "Ошибка конвертации, попробуйте снова.";
- string requestInputNumber = "Введите число: ";
- string userInput;
- bool resultConverted = false;
- int number = 0;
- while (resultConverted == false)
- {
- Console.Write(requestInputNumber);
- userInput = Console.ReadLine();
- resultConverted = int.TryParse(userInput, out int numberConvert);
- if (resultConverted != true)
- {
- Console.WriteLine(errorConversion);
- }
- else
- {
- number = numberConvert;
- }
- }
- return number;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement