Hello, I’m working on this task:
Your program should read two integers each from a new line. Then, it should output the sum, difference, product and quotient of these numbers. Put your code in the try block. Add a catch block that catches a DivideByZeroException and prints to the screen “Can’t divide by zero!”
Example 1:
>12
>4
16
8
48
3
Example 2:
>12
>0
12
12
0
Can’t divide by zero!
Here is my code:
namespace Exceptions
{
public class DontDivideByZero2
{
public static void Main(string[] args)
{
try
{
int a = int.Parse(Console.ReadLine());
int b = int.Parse(Console.ReadLine());
int sum = a + b;
int difference = a - b;
int product = a * b;
int quotient = a / b;
Console.WriteLine(sum);
Console.WriteLine(difference);
Console.WriteLine(product);
Console.WriteLine(quotient);
}
catch (DivideByZeroException)
{
Console.WriteLine("Can't divide by zero!");
}
}
}
}
Can anyone please help me to solve it?