示例#1
0
        private void EqualsButton_Click(object sender, RoutedEventArgs e)
        {
            double newNumber;

            if (double.TryParse(resultLabel.Content.ToString(), out newNumber))
            {
                switch (selectedOperator)
                {
                case SelectedOperator.Addition:
                    result = SimpleMath.Add(lastNumber, newNumber);
                    break;

                case SelectedOperator.Subtraction:
                    result = SimpleMath.Subtract(lastNumber, newNumber);
                    break;

                case SelectedOperator.Multiplication:
                    result = SimpleMath.Multiply(lastNumber, newNumber);
                    break;

                case SelectedOperator.Division:
                    result = SimpleMath.Divide(lastNumber, newNumber);
                    break;
                }

                resultLabel.Content = result.ToString();
            }
        }
        private void EqualsButton_Click(object sender, RoutedEventArgs e)
        {
            // Get the second value.
            double newNumber;

            if (double.TryParse(ResultLabel.Content.ToString(), out newNumber))
            {
                // Perform the operation now
                switch (_selectedOperation)
                {
                case CalculatorOperation.Addition:
                    _result = SimpleMath.Add(_lastNumber, newNumber);
                    break;

                case CalculatorOperation.Subtraction:
                    _result = SimpleMath.Subtract(_lastNumber, newNumber);
                    break;

                case CalculatorOperation.Multiplication:
                    _result = SimpleMath.Multiply(_lastNumber, newNumber);
                    break;

                case CalculatorOperation.Division:
                    _result = SimpleMath.Divide(_lastNumber, newNumber);
                    break;
                }

                ResultLabel.Content = _result.ToString();
            }
        }
示例#3
0
        private void EqButton_Click(object sender, RoutedEventArgs e)
        {
            if (double.TryParse(resultLabel.Content.ToString(), out double newNumber))
            {
                switch (SelectedFunction)
                {
                case SelectedFunction.Addition:
                    result = SimpleMath.Add(lastNumber, newNumber);
                    break;

                case SelectedFunction.Subtraction:
                    result = SimpleMath.Subtract(lastNumber, newNumber);
                    break;

                case SelectedFunction.Multiplication:
                    result = SimpleMath.Mult(lastNumber, newNumber);
                    break;

                case SelectedFunction.Division:
                    result = SimpleMath.Div(lastNumber, newNumber);
                    break;
                }

                resultLabel.Content = result.ToString();
            }
        }
示例#4
0
        private void EqualsButtonClick(object sender, RoutedEventArgs e)
        {
            double newNumber;

            if (double.TryParse(ResultLabel.Content.ToString(), out newNumber))
            {
                switch (selectedOperator)
                {
                case SelectedOperator.Plus:
                    result = SimpleMath.Add(lastNumber, newNumber);
                    break;

                case SelectedOperator.Minus:
                    result = SimpleMath.Subtract(lastNumber, newNumber);
                    break;

                case SelectedOperator.Multiply:
                    result = SimpleMath.Multiply(lastNumber, newNumber);
                    break;

                case SelectedOperator.Divide:
                    result = SimpleMath.Divide(lastNumber, newNumber);
                    break;

                default:
                    ResultLabel.Content = "0";
                    lastNumber          = 0;
                    result = 0;
                    break;
                }

                ResultLabel.Content = result.ToString();
            }
        }
示例#5
0
        private void _buttonEqual_Click(object sender, RoutedEventArgs e)
        {
            if (double.TryParse(labelResult.Content.ToString(), out double newNumber))
            {
                switch (_operator)
                {
                case Operator.Addition:
                    _result = SimpleMath.Add(_lastNumber, newNumber);
                    break;

                case Operator.Division:
                    _result = SimpleMath.Divide(_lastNumber, newNumber);
                    break;

                case Operator.Multiplication:
                    _result = SimpleMath.Multiply(_lastNumber, newNumber);
                    break;

                case Operator.Subtraction:
                    _result = SimpleMath.Subtract(_lastNumber, newNumber);
                    break;
                }

                labelResult.Content = _result.ToString();
            }
        }
示例#6
0
        private void EqualButton_Click(object sender, RoutedEventArgs e)
        {
            equalButtonPressed     = true;
            operationButtonPressed = false;

            if (double.TryParse(resultLabel.Content.ToString(), out secondOperand))
            {
                switch (selectedOperator)
                {
                case SelectedOperator.Addition:
                    calculationResult = SimpleMath.Add(firstOperand, secondOperand);
                    break;

                case SelectedOperator.Subtraction:
                    calculationResult = SimpleMath.Subtract(firstOperand, secondOperand);
                    break;

                case SelectedOperator.Multiplication:
                    calculationResult = SimpleMath.Multiply(firstOperand, secondOperand);
                    break;

                case SelectedOperator.Division:
                    calculationResult = SimpleMath.Divide(firstOperand, secondOperand);
                    break;

                default:
                    break;
                }

                resultLabel.Content = calculationResult.ToString();
            }
        }