I am having trouble with types in c#. I have an int input on a console application and I would like for a (non-numeral characters) string input to be put back into my existing but not pictured do while loop like an error. I don't want to convert nonnumeral string values to int, but rather want to protect my object from crashing and return it to the beginning of my loop when an unacceptable value (i.e. a alphabetic string value) is presented. For example:
Console.WriteLine("Please input an odd number:");
int input1 = int.Parse(Console.ReadLine());
if (input1 % 2 == 0)
{
Console.WriteLine("Please input an odd number.");
//is even
}
else
{
TotalOdd = TotalOdd + input1;
TotalNumeral++;
Console.WriteLine("Accepted.");
//is odd
}
I would like for a string input to be treated like an "even" number. I know this seems like an amateurish mistake, but I am actually at a loss... Any help is appreciated.