0

I'm trying to make an If-else statement to parse input as "int", but I also want to resolve the exceptions. What if the input is a string? How can I make my computer reading different values in order to decide whether the input is right or wrong?

Thank you.

static void NumberApp()
{
    Console.Write("Choose a number, I'll count from that to 100: ");
    int number = Convert.ToInt32(Console.ReadLine()); // How can I correct this?

    if (number >= 100)
    {
        Console.WriteLine("Choose a number lower than 100.\n");
        NumberApp();
    }

    else if (number < 100)
    {
        for (int i = number; i < 100; i++)
        {
            Console.Write(i + " ");
        }
        Console.Write("100.");
    }

    else if (number is string) //Error?
    {
        Console.WriteLine("Choose an integer\n");
        NumberApp();
    }
}
Kache
  • 15,647
  • 12
  • 51
  • 79

0 Answers0