Answer to Question #289189 in C# for Chitti

Question #289189

Amit wants to develop an arithmetic calculator to perform some arithmetic functions. Develop a program to achieve the same

1
Expert's answer
2022-01-20T08:27:41-0500
using System;
using System.Collections.Generic;


namespace App
{


    class Program
    {
        static void Main(string[] args)
        {


            Console.WriteLine("1 - Addition");
            Console.WriteLine("2 - Subtraction");
            Console.WriteLine("3 - Multiplication");
            Console.WriteLine("4 - Division");
            Console.Write("Select the action: ");
            int action = Convert.ToInt32(Console.ReadLine());
            Console.Write("Enter number 1: ");
            float number1 = float.Parse(Console.ReadLine());
            Console.Write("Enter number 2: ");
            float number2 = float.Parse(Console.ReadLine());
            float result = 0;
            switch (action)
            {
                case 1:
                    {
                        result = Addition(number1, number2);
                        break;
                    }
                case 2:
                    {
                        result = Subtraction(number1, number2);
                        break;
                    }
                case 3:
                    {
                        result = Multiplication(number1, number2);
                        break;
                    }
                case 4:
                    {
                        result = Division(number1, number2);
                        break;
                    }
                default:
                    Console.WriteLine("Wrong action!! try again");
                    break;
            }
            Console.WriteLine("The result is {0}", result);
            Console.ReadKey();
        }
        //Addition  
        public static float Addition(float number1, float number2)
        {
            return number1 + number2;


        }
        //Substraction  
        public static float Subtraction(float number1, float number2)
        {
            return number1 - number2;
        }
        //Multiplication  
        public static float Multiplication(float number1, float number2)
        {
            return number1 * number2;
        }
        //Division  
        public static float Division(float number1, float number2)
        {
            return number1 / number2;
        }




    }
}

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