vendredi 8 juin 2018

C# reading Integer input

I would just like some quick help regarding user integer input. If I use string I dont have a problem but when I try to convert it into an int number the program crashes. any fast fixes?

string a = Console.ReadLine();
int age = Convert.ToInt32(a);
Console.WriteLine("What is your age?" + age);

if ((age >= 1) && (age <= 6))
{
    Console.WriteLine("you are in Preschool");
}
else if ((age == 7) && (age >= 13))
{
    Console.WriteLine("you are in Elementary School");
}
else if ((age == 14) && (age >= 18))
{
    Console.WriteLine("You are in High School");
}
else if ((age == 19) && (age >= 26))
{
    Console.WriteLine("You are probably in College");
}
else
{
    Console.WriteLine("you probaby have graduated already");
}

Aucun commentaire:

Enregistrer un commentaire