Answer the question
In order to leave comments, you need to log in
How to do input validation and draw a table?
Good evening!
Tell me how to check that an integer is entered, and not a fractional or a letter? At the moment, when you enter something that is not a whole program crashes.
And how to draw a table so that there is text inside it in the center with indents along the edges and the width of the table depends on the entered text with a limit on the number of characters?
I'm stuck for now. Guide me please.
using System;
namespace ConsoleApp_HW03
{
class Program
{
static void Main(string[] args)
{
while (true)
{
Console.Write("Введите размерность таблицы: ");
var table = Console.ReadLine();
var number = int.Parse(table);
if (number % 2 == 0 && number <= 6)
{
Console.Write($"Введите произвольный текст: ");
string text;
while ((text = Console.ReadLine()) != string.Empty)
{
switch (text.Length)
{
case <= 40:
Console.WriteLine("В яблочко!");
break;
case > 40:
Console.Write("Перелет. Попробуйте снова: ");
break;
}
}
}
else
{
Console.WriteLine($"Неприемлимое значение. Попробуйте еще раз.");
}
}
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question