Divide two numbers entered by the user The main part of the

Divide two numbers entered by the user. The \'main\' part of the program will accept the numbers and convert them to Integers. These numbers will then be \'passed\' to a module (divider), which will divide the numbers and \'return\' the result back to the \'main\' part of the program. The \'main\' part of the program will then pass the result into a second module (displayer), which will display the result, in a format similar to \"The result of your calculation is 25\". Since the user could enter a zero for the denominator, You MUST include a try/catch block which surrounds the \'call\' to the divider module in the \'main\' part of the program. It is OK for it to surround all the code in the \'main\' part of the program. The \'catch\' block should display either the default message created by C#, or your own message telling the user not to enter a zero for the denominator

Solution

//take one console application

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace arithematicexception
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(\"enter the nominator nos only\");
int no = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(\"enter the denominator in nos only\");
int no1 = Convert.ToInt32(Console.ReadLine());
try
{
int result = no / no1;
Console.WriteLine(\"the result is :\" + result);
}catch(DivideByZeroException)
{
Console.WriteLine(\"divide by zero not possible\");
}
finally
{
Console.WriteLine(\"you must enter denominator not equal to zero\");
}
Console.ReadKey();

}
}
}

output

enter the nominator nos only
25
enter the denominator in nos only
0
divide by zero not possible
you must enter denominator not equal to zero

Divide two numbers entered by the user. The \'main\' part of the program will accept the numbers and convert them to Integers. These numbers will then be \'pass

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site