예제 #1
0
        private void Result_Click(object sender, EventArgs e)
        {
            if (
                Number1.Text == "" ||
                CalculateDisplay.Text == "" ||
                operation == "" ||
                (Number1.Text == "" && operation == "") ||
                (CalculateDisplay.Text == "" && operation == "")
                )
            {
                Number1.Text = "Error :Value is empty";
                Error.Text   = "Clear me =>";
            }
            else
            {
                switch (operation)
                {
                case "+":
                    CalculateDisplay.Text = (MathCalculater.Addition(Convert.ToInt32(Number1.Text), Convert.ToInt32(CalculateDisplay.Text))) + "";
                    break;

                case "-":
                    CalculateDisplay.Text = (MathCalculater.Subtraction(Convert.ToInt32(Number1.Text), Convert.ToInt32(CalculateDisplay.Text))) + "";
                    break;

                case "*":
                    CalculateDisplay.Text = (MathCalculater.Multiplication(Convert.ToInt32(Number1.Text), Convert.ToInt32(CalculateDisplay.Text))) + "";
                    break;

                case "/":
                    if (Number1.Text != "" && CalculateDisplay.Text == "0")
                    {
                        Number1.Text   = "";
                        Operation.Text = "";
                        Error.Text     = "Sorry, Error! On 0 division is imposible";
                    }
                    else if (Convert.ToInt32(Number1.Text) % 2 != 0)
                    {
                        CalculateDisplay.Text = Convert.ToDouble(Number1.Text) / Convert.ToDouble(CalculateDisplay.Text) + "";
                    }
                    else
                    {
                        CalculateDisplay.Text = (MathCalculater.Division(Convert.ToInt32(Number1.Text), Convert.ToInt32(CalculateDisplay.Text))) + "";
                    }
                    break;

                case "^":
                    CalculateDisplay.Text = (MathCalculater.Sqrt(Convert.ToInt32(Number1.Text), Convert.ToInt32(CalculateDisplay.Text))) + "";
                    break;

                default:
                    Error.Text = "Я хз что ты сделал и как ты меня сломал";
                    break;
                }
            }
            Number1.Text   = "";
            Operation.Text = "";
            Error.Text     = "";
            operation      = "";
        }
예제 #2
0
        public static double ResultEquals(string number, string number2, string operation)
        {
            double result = 0;

            switch (operation)
            {
            case "+":
                result = MathCalculater.Addition(Convert.ToInt32(number), Convert.ToInt32(number2));
                break;

            case "-":
                result = MathCalculater.Subtraction(Convert.ToInt32(number), Convert.ToInt32(number2));
                break;

            case "*":
                result = MathCalculater.Multiplication(Convert.ToInt32(number), Convert.ToInt32(number2));
                break;

            case "/":
                if (Convert.ToInt32(number) % 2 != 0)
                {
                    result = Convert.ToDouble(number) / Convert.ToDouble(number2);
                }
                else
                {
                    result = MathCalculater.Division(Convert.ToInt32(number), Convert.ToInt32(number2));
                }
                break;

            case "^":
                result = MathCalculater.Sqrt(Convert.ToInt32(number), Convert.ToInt32(number2));
                break;

            default:
                break;
            }
            return(result);
        }