I\'m trying to restrict the user to only input 5 digits into the console for C#. I have my code error check the user, but for some reason after I type let\'s say...6 digits, the
You are accessing console multiple times. Check for length of your captured input - temp
. Try this:
var temp = Console.ReadLine();
while (temp.Length > 5)
{
Console.WriteLine("Error. Zip code is not 5 digits. Please enter a valid number.");
temp = Console.ReadLine();
}
address.zipCode = int.Parse(temp);