What I would really like to do is check to see if the value entered is in fact an integer, and if it's not an integer, show a message on the screen and keep looping until I do enter in an integer. So the screen will look like this:
Enter first integer: t
Sorry. You must enter an integer.
Enter first integer: s
Sorry. You must enter an integer.
I'm not familiar at all with error checking so this is kind of hard. Here is my program:
public static void Main()
{
int x = 0;
int y = 0;
try
{
Console.Write("Enter first integer: ");
x = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter second integer: ");
y = Convert.ToInt32(Console.ReadLine());
}
catch
{
}
Console.WriteLine();
if (x == y)
Console.WriteLine("{0} == {1}", x, y);
if (x != y)
Console.WriteLine("{0} != {1}", x, y);
if (x < y)
Console.WriteLine("{0} < {1}", x, y);
if (x > y)
Console.WriteLine("{0} > {1}", x, y);
if (x <= y)
Console.WriteLine("{0} <= {1}", x, y);
if (x >= y)
Console.WriteLine("{0} >= {1}", x, y);
Console.WriteLine();
}

New Topic/Question
Reply




MultiQuote




|