using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace CSharpGreatestNumber { class Program { static void Main(string[] args) { //try...catch: is used to catch any unexpected behavior during execution time. // WHEN an exception is thrown inside the "try" block, the code inside the "catch" block // is executed instead of halting the program // In our case here, when the user enters a non-integer operand a format exception // will be thrown and catched try { //Declaring variables int intFirst; int intSecond; int intThird; //Holder of the maximum value among the 3 integers int maxValue; //Prompt the user to enter the first integer Console.WriteLine("Please enter the first integer: "); intFirst = int.Parse(Console.ReadLine()); //Prompt the user to enter the second integer Console.WriteLine("Please enter the second integer: "); intSecond = int.Parse(Console.ReadLine()); //Prompt the user to enter the third integer Console.WriteLine("Please enter the third integer: "); intThird = int.Parse(Console.ReadLine()); //Getting the max value //Compare the numbers to find out which is the highest number maxValue = intFirst; if (intSecond > maxValue) maxValue = intSecond; if (intThird > maxValue) maxValue = intThird; //Show the largest Number Console.WriteLine("\nThe largest number entered is: {0}\n", maxValue); } catch (FormatException) { //Alert the user that he didn't enter a whole number Console.WriteLine("You didn't enter a whole number!"); }//End of catch Console.WriteLine("Please press any key to Exit"); Console.Read(); } } }