I'm trying to create a program that asking users to enter their name which it has to be < 30 characters and can not to be empty or numeric value .The problem is when I'm running it even if i enter a numeric value it says "name successfully accepted".I really do not know where i'm doing wrong .if You could help i really appreciate it.
String name ;
bool testname = true;
while (testname)
{
Console.WriteLine("plz enter a name");
name = Console.ReadLine();
if (name.Length < 30 && name.Length == 0)
{
Console.WriteLine("the input can not be more 30 character or empty ");
}
else
{
bool numeric = true;
int checkname;
numeric = Int32.TryParse(name, out checkname);
if (numeric == false)
{
Console.WriteLine(" name successfully accepted");
testname= false;
}
else
{
Console.WriteLine("Please enter alphabetic characters only");
}
Console.ReadKey();
}
}
Aucun commentaire:
Enregistrer un commentaire