Answer to Question #297227 in C# for keith

Question #297227

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).


1
Expert's answer
2022-02-13T11:07:48-0500
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);
        }
    }

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS