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 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 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.Substraction: result = SimpleMath.Sub(lastNumber, newNumber); break; case SelectedOperator.Multiplication: result = SimpleMath.Multi(lastNumber, newNumber); break; case SelectedOperator.Division: result = SimpleMath.Div(lastNumber, newNumber); break; } resultLabel.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) { 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; } }