Write a program that mimics a calculator. The program should take as input two integers and the
operation to be performed. It should then output the number, the operator and the result. (For division,
if the denominator is zero, output an appropriate message).
class Program
{
static void Сalculator(double a, char oper, double b)
{
if (oper == '+')
{
Console.WriteLine($"Sum = {a + b}");
}
else if (oper == '-')
{
Console.WriteLine($"Diff = {a - b}");
}
else if (oper == '*')
{
Console.WriteLine($"Multi = {a * b}");
}
else if (oper == '/')
{
if (b == 0)
{
Console.WriteLine("Denominator is zero");
}
else
{
Console.WriteLine($"Div = {a / b}");
}
}
}
static void Main(string[] args)
{
Console.WriteLine("Enter a: ");
double a = int.Parse(Console.ReadLine());
Console.WriteLine("Enter operation: ");
char oper = char.Parse(Console.ReadLine());
Console.WriteLine("Enter b: ");
double b = int.Parse(Console.ReadLine());
Сalculator(a, oper, b);
}
}
Comments
Leave a comment