static void Main(string[] args)
        {
            CalculatorClass calc = new CalculatorClass();

            Console.WriteLine("Testing Addition - calc.Add(x,x)");
            Console.WriteLine($"8 + 2 = {calc.Add(8, 2)}");
            Console.WriteLine($"909 + 525 = {calc.Add(909, 525)}");
            Console.WriteLine($"352 + 86 = {calc.Add(352, 86)}");
            Console.WriteLine($"155 + 35 = {calc.Add(155, 35)}\n");


            Console.WriteLine("Testing Subtract - calc.Subtract(x,x)");
            Console.WriteLine($"8 - 2 = {calc.Subtract(8, 2)}");
            Console.WriteLine($"55 - 5 = {calc.Subtract(55, 5)}");
            Console.WriteLine($"25 - 86 = {calc.Subtract(25, 86)}");
            Console.WriteLine($"155 - 5 = {calc.Subtract(155, 5)}\n");


            Console.WriteLine("Testing Multiply - calc.Multiply(x,x)");
            Console.WriteLine($"8 * 2 = {calc.Multiply(8, 2)}");
            Console.WriteLine($"9 * 5 = {calc.Multiply(9, 5)}");
            Console.WriteLine($"2 * 86 = {calc.Multiply(2, 86)}");
            Console.WriteLine($"54 * 5 = {calc.Multiply(54, 5)}\n");


            Console.WriteLine("Testing Power - calc.Power(x,x)");
            Console.WriteLine($"5 power 2 = {calc.Power(5, 2)}");
            Console.WriteLine($"25 power 4 = {calc.Power(25, 4)}");
            Console.WriteLine($"25 power 6 = {calc.Power(25, 6)}");
            Console.WriteLine($"14 power 2 = {calc.Power(14, 2)}\n");
        }
예제 #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            CalculatorClass calc = new CalculatorClass();

            Console.WriteLine($"2+7 = {calc.Add(2, 7)}");
            Console.WriteLine($"12-2 = {calc.Subtract(12, 2)}");
            Console.WriteLine($"4*5 = {calc.Multiply(4, 5)}");
            Console.WriteLine($"5^3 = {calc.Power(5, -3)}");
        }
예제 #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to the calculator!");

            CalculatorClass Calculator = new CalculatorClass();

            while (true)
            {
                Console.WriteLine("Choose operation:");
                Console.WriteLine("1: Add");
                Console.WriteLine("2: Subtract");
                Console.WriteLine("3: Multiply");
                Console.WriteLine("4: Divide");
                Console.WriteLine("5: Power");

                double switchVar = Convert.ToDouble(Console.ReadLine());

                Console.WriteLine("First number:");
                double a = Convert.ToDouble(Console.ReadLine());

                Console.WriteLine("Second number:");
                double b = Convert.ToDouble(Console.ReadLine());

                double result;

                switch (switchVar)
                {
                case 1:
                    result = Calculator.Add(a, b);
                    break;

                case 2:
                    result = Calculator.Subtract(a, b);
                    break;

                case 3:
                    result = Calculator.Multiply(a, b);
                    break;

                case 4:
                    try
                    {
                        result = Calculator.Divide(a, b);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                    }
                    finally
                    {
                        result = 0;
                    }
                    break;

                case 5:
                    result = Calculator.Power(a, b);
                    break;

                default:
                    result = 0;
                    break;
                }

                Console.WriteLine("Result: " + result);
                Console.WriteLine();
            }
        }