private void EqualsButton_Click(object sender, RoutedEventArgs e) { double newNumber; expressionLabel.Content = $"{expressionLabel.Content}="; if (double.TryParse(resultLabel.Content.ToString(), out newNumber)) { switch (selectedOperator) { case SelectedOperator.Addtion: result = SimpleMath.Add(lastNumber, newNumber); break; case SelectedOperator.Subtraction: result = SimpleMath.Sub(lastNumber, newNumber); break; case SelectedOperator.Multiplication: result = SimpleMath.Mul(lastNumber, newNumber); break; case SelectedOperator.Division: result = SimpleMath.Div(lastNumber, newNumber); break; } resultLabel.Content = result.ToString(); equalsClicked = true; } }
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 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 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(); } }
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 BtnEquals_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.Subtraction: result = SimpleMath.Minus(lastNumber, newNumber); break; case SelectedOperator.Multiplication: result = SimpleMath.Times(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 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(); } }
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 BtnEquals_Click(object sender, RoutedEventArgs e) { if (lastNumber != 0) { if (newNumber == 0) { newNumber = Convert.ToDouble(lblResult.Content.ToString()); } switch (selectedOperator) { case SelectedOperator.Multiplication: lblResult.Content = SimpleMath.Multiplicate(lastNumber, newNumber); break; case SelectedOperator.Substraction: lblResult.Content = SimpleMath.Sustract(lastNumber, newNumber); break; case SelectedOperator.Addition: lblResult.Content = SimpleMath.Add(lastNumber, newNumber); break; case SelectedOperator.Division: lblResult.Content = SimpleMath.Divide(lastNumber, newNumber); break; } lastNumber = Convert.ToDouble(lblResult.Content.ToString()); newNumber = 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(); } }
private void EqualBtn_Click(object sender, RoutedEventArgs e) { double newNum; if (double.TryParse(resultLb.Content.ToString(), out newNum)) { switch (selectedOperator) { case selectedOperator.Addition: result = SimpleMath.Add(lastNum, newNum); break; case selectedOperator.Soustraction: result = SimpleMath.Sous(lastNum, newNum); break; case selectedOperator.Multiplication: result = SimpleMath.Multi(lastNum, newNum); break; case selectedOperator.Division: result = SimpleMath.Div(lastNum, newNum); break; } } resultLb.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(); } }
// = 버튼 private void EqualButton_Click(object sender, RoutedEventArgs e) { double newNumber = 0; double result = double.Parse(resultLable.Content.ToString()); if (double.TryParse(resultLable.Content.ToString(), out newNumber)) { switch (selectedOperator) { case SelectedOperator.Addition: result = SimpleMath.Add(lastValue, newNumber); state.Items.Add(resultexp.Content.ToString() + newNumber + "=" + result.ToString()); resultexp.Content = ""; break; case SelectedOperator.Substraction: result = SimpleMath.Sub(lastValue, newNumber); state.Items.Add(resultexp.Content.ToString() + newNumber + "=" + result.ToString()); resultexp.Content = ""; break; case SelectedOperator.Multipication: result = SimpleMath.Mul(lastValue, newNumber); state.Items.Add(resultexp.Content.ToString() + newNumber + "=" + result.ToString()); resultexp.Content = ""; break; case SelectedOperator.Division: result = SimpleMath.Div(lastValue, newNumber); state.Items.Add(resultexp.Content.ToString() + newNumber + "=" + result.ToString()); resultexp.Content = ""; break; } resultLable.Content = result.ToString(); lastValue = 0; tmp = 0; Flag = 0; Flag2 = 0; } }
}//이벤트 등록 //연산자 함수 private void OperationButton_Click(object sender, RoutedEventArgs e) { //lastValue = double.Parse(resultLable.Content.ToString()); //resultLable.Content = "0"; if (double.TryParse(resultLable.Content.ToString(), out lastValue)) { resultLable.Content = "0"; } if (sender == addButton) { if (Flag == 0) { selectedOperator = SelectedOperator.Addition; resultexp.Content += lastValue + "+"; Flag++; result = lastValue; tmp += lastValue; Flag2 = 1; } else { if (Flag2 == 1) { selectedOperator = SelectedOperator.Addition; tmp = SimpleMath.Add(tmp, lastValue); resultexp.Content += lastValue + "+"; } else if (Flag2 == 2) { selectedOperator = SelectedOperator.Addition; tmp = SimpleMath.Sub(tmp, lastValue); resultexp.Content += lastValue + "+"; } else if (Flag2 == 3) { selectedOperator = SelectedOperator.Addition; tmp = SimpleMath.Mul(tmp, lastValue); resultexp.Content += lastValue + "+"; } else { selectedOperator = SelectedOperator.Addition; tmp = SimpleMath.Div(tmp, lastValue); resultexp.Content += lastValue + "+"; } } Flag2 = 1; } if (sender == subButton) { if (Flag == 0) { selectedOperator = SelectedOperator.Substraction; resultexp.Content += lastValue + "-"; Flag++; result = lastValue; tmp += lastValue; Flag2 = 2; } else { if (Flag2 == 1) { selectedOperator = SelectedOperator.Substraction; tmp = SimpleMath.Add(tmp, lastValue); resultexp.Content += lastValue + "-"; } else if (Flag2 == 2) { selectedOperator = SelectedOperator.Substraction; tmp = SimpleMath.Sub(tmp, lastValue); resultexp.Content += lastValue + "-"; } else if (Flag2 == 3) { selectedOperator = SelectedOperator.Substraction; tmp = SimpleMath.Mul(tmp, lastValue); resultexp.Content += lastValue + "-"; } else { selectedOperator = SelectedOperator.Substraction; tmp = SimpleMath.Div(tmp, lastValue); resultexp.Content += lastValue + "-"; } } Flag2 = 2; } if (sender == mulButton) { if (Flag == 0) { selectedOperator = SelectedOperator.Multipication; resultexp.Content += lastValue + "*"; Flag++; result = lastValue; tmp = lastValue; Flag2 = 3; } else { if (Flag2 == 1) { selectedOperator = SelectedOperator.Multipication; tmp = SimpleMath.Add(tmp, lastValue); resultexp.Content += lastValue + "*"; } else if (Flag2 == 2) { selectedOperator = SelectedOperator.Multipication; tmp = SimpleMath.Sub(tmp, lastValue); resultexp.Content += lastValue + "*"; } else if (Flag2 == 3) { selectedOperator = SelectedOperator.Multipication; tmp = SimpleMath.Mul(tmp, lastValue); resultexp.Content += lastValue + "*"; } else { selectedOperator = SelectedOperator.Multipication; tmp = SimpleMath.Div(tmp, lastValue); resultexp.Content += lastValue + "*"; } } Flag2 = 3; } if (sender == divButton) { if (Flag == 0) { selectedOperator = SelectedOperator.Division; resultexp.Content += lastValue + "/"; Flag++; result = lastValue; tmp = lastValue; Flag2 = 4; } else { if (Flag2 == 1) { selectedOperator = SelectedOperator.Division; tmp = SimpleMath.Add(tmp, lastValue); resultexp.Content += lastValue + "/"; } else if (Flag2 == 2) { selectedOperator = SelectedOperator.Division; tmp = SimpleMath.Sub(tmp, lastValue); resultexp.Content += lastValue + "/"; } else if (Flag2 == 3) { selectedOperator = SelectedOperator.Division; tmp = SimpleMath.Mul(tmp, lastValue); resultexp.Content += lastValue + "/"; } else { selectedOperator = SelectedOperator.Division; tmp = SimpleMath.Div(tmp, lastValue); resultexp.Content += lastValue + "/"; } } Flag2 = 4; } }