Пример #1
0
        private void EqualsButton_Click(object sender, RoutedEventArgs e)
        {
            double newNumber;

            //checks and parses the string into a double if the string contains only charactors allowed in a double
            if (double.TryParse(ResultLable.Content.ToString(), out newNumber))
            {
                switch (mathOperator)
                {
                case SelectedOperator.Addition:
                    result = SimpleMath.Add(lastNumber, newNumber);
                    break;

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

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

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

                ResultLable.Content = result.ToString();
            }
        }
Пример #2
0
        private void resultButton_Click(object sender, RoutedEventArgs e)
        {
            //Checks which operation was used, and after calculates it by using another "SimpleMath" class

            double newNumber;

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

                case SelectedOperator.Substraction:
                    result = SimpleMath.substract(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();
            }
        }