private void EqualsBtn_Click(object sender, RoutedEventArgs e) { if (double.TryParse(resultLabel.Content.ToString(), out double newNumber)) { switch (SelectedOperator) { case SelectedOperator.Sum: result = SimpleMath.Sum(lastNumber, newNumber); break; case SelectedOperator.Subtract: result = SimpleMath.Substract(lastNumber, newNumber); break; case SelectedOperator.Multiply: result = SimpleMath.Multiply(lastNumber, newNumber); break; case SelectedOperator.Divide: result = SimpleMath.Divide(lastNumber, newNumber); break; } resultLabel.Content = result; } }
private void EqualButton_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.Sustraction: result = SimpleMath.Sustraction(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 BtnEqual_Click(object sender, RoutedEventArgs e) { double currentNumber, result; if (double.TryParse(lblResult.Content.ToString().Replace(",", "."), out currentNumber)) { switch (SelOper) { case SelectedOperator.Addition: result = SimpleMath.Add(lastNumber, currentNumber); break; case SelectedOperator.Substraction: result = SimpleMath.Substract(lastNumber, currentNumber); break; case SelectedOperator.Multiplication: result = SimpleMath.Multiply(lastNumber, currentNumber); break; case SelectedOperator.Divition: result = SimpleMath.Divide(lastNumber, currentNumber); break; case SelectedOperator.None: result = 0; break; default: result = 0; break; } lblResult.Content = result.ToString().Replace(",", "."); } }
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(); } }
private void BtnCalculate_Click(object sender, RoutedEventArgs e) { double newNumber; if (double.TryParse(lblResult.Content.ToString(), out newNumber)) { switch (SelectedOperator) { case SelectedOperator.Addition: result = SimpleMath.Add(lastNumber, newNumber); break; case SelectedOperator.Substraction: result = SimpleMath.Substraction(lastNumber, newNumber); break; case SelectedOperator.Multiplication: result = SimpleMath.Multiply(lastNumber, newNumber); break; case SelectedOperator.Division: result = SimpleMath.Divide(lastNumber, newNumber); break; } lblResult.Content = result.ToString(); } }
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(); } }
private void Equal_Click(object sender, RoutedEventArgs e) { if (double.TryParse(Result.Text.ToString(), out double newNumber)) // Declaração do número novo dentro do argumento { 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; } } Result.Text = $"{_result}"; }
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(); } }
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(); } }