This code currently handles inputs of numbers just fine whether greater or less or within the accepted range, however, the program crashes when anything that isn't a number is entered with an unhandled exception error.System.FormatException: 'Input string was not in a correct format.' That's the error if that helps at all.
using System;
class Program
{
static void PrintHello(int NumberOfTimes)
{
if (NumberOfTimes > 1 && NumberOfTimes < 11)
{
for (int Counter = 0; Counter < NumberOfTimes; Counter++)
{
Console.WriteLine("Hello.");
}
}
else { Console.WriteLine("Error, please enter a number between 1 and 10"); }
}
static void Main(string[] args)
{
int myNumber = 1;
while (myNumber != 0)
{
Console.WriteLine("Enter a number between 1 and 10, or 0 to stop");
myNumber = Convert.ToInt16(Console.ReadLine());
PrintHello(myNumber);
}
}
}