Esempio n. 1
0
        private void ProcessOperatorCommand(string value)
        {
            try
            {
                switch (value)
                {
                case "Clear":
                    TopInput      = "";
                    OperatorInput = "";
                    BottomInput   = "";
                    Answer        = 0;
                    ErrorMessage  = "";
                    break;

                case "Calculate":
                    if (!string.IsNullOrEmpty(OperatorInput))
                    {
                        switch (OperatorInput)
                        {
                        case "+":
                            Answer = Math.Round(TopInputDecimal() + BottomInputDecimal(), 2);
                            break;

                        case "-":
                            Answer = Math.Round(TopInputDecimal() - BottomInputDecimal(), 2);
                            break;

                        case "*":
                            Answer = Math.Round(TopInputDecimal() * BottomInputDecimal(), 2);
                            break;

                        case "/":
                            Answer = Math.Round(TopInputDecimal() / BottomInputDecimal(), 2);
                            break;
                        }
                    }
                    else
                    {
                        Answer = TopInputDecimal();
                    }

                    TopInput = Answer.ToString();

                    break;

                case "+":
                case "-":
                case "*":
                case "/":
                    BottomInput   = "";
                    OperatorInput = value;
                    break;
                }
            }
            catch (ArithmeticException e)
            {
                ErrorMessage = e.Message;
            }
            catch (Exception e)
            {
                ErrorMessage = e.Message;
            }
        }