Question: // Prevents non-numeric data entry // Then prevents division by 0 using System; using static System.Console; class DebugEleven02 { static void Main() { int num

// Prevents non-numeric data entry // Then prevents division by 0 using System; using static System.Console; class DebugEleven02 { static void Main() { int num = 0, denom = 0; string dataEntry; double result; bool dataEntryIsValid = false; while (!dataEntryIsValid) { try { WriteLine("Enter a number"); dataEntry = ReadLine(); result = num * 1.0 / denom; dataEntryIsValid = true; } catch (FormatException ) { WriteLine("Invalid entry - please enter numbers"); } } try { result = num * 1.0 / denom; WriteLine("Division is successful"); } catch (DivideByZeroException ) { WriteLine("Division failed"); result = 0; } WriteLine("Result is {0}", result); } public static void DataEntry(int num, int denom) { Console.Write("Enter a number "); if (!int.TryParse(Console.ReadLine(), out num)) Console.WriteLine("Numerator was set to 0"); Console.Write("Enter a number to divide into the first "); if (int.TryParse(Console.ReadLine(), out denom)) Console.WriteLine("Denominator was set to 0"); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!