using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace CSharpSumOf2Numbers { 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 valueOne; int valueTwo; int sum; //Prompt the user to enter the first operand System.Console.WriteLine("Please Enter a Whole Number: "); //Fetch the number entered by the user, convert it to an integer and set it to the variable "valueOne" valueOne = int.Parse(Console.ReadLine()); //Prompt the user to enter the second operand System.Console.WriteLine("Please Enter a Whole Number: "); //Fetch the number entered by the user, convert it to an integer and set it to the variable "valueTwo" valueTwo = int.Parse(Console.ReadLine()); //Calculate the sum of the 2 operands and set it to the variable "sum" sum = valueOne + valueTwo; //Check if the sum is greater than 0 then print the operands and the sum if (sum > 0) { Console.WriteLine("The sum of valueOne: {0} and valueTwo: {1} is Equal to: {2}", valueOne, valueTwo, sum); } else //Else if the sum is NOT greater than 0, { Console.WriteLine("Both values were Zero!"); } }//End of try block catch(System.FormatException) { //The user has entered a non-integer number. //Alert the user that he didn't enter a whole number Console.WriteLine("You didn't enter a whole number!"); }//End of catch //Exit The program when user clicks on any key Console.WriteLine("Please press any key to Exit"); Console.Read(); }//End of main method } }