private void EqualButton_Click(object sender, RoutedEventArgs e) { double newNumber = lastNumber; if (double.TryParse(resultLabel.Content.ToString(), out lastNumber)) { switch (selectedOperator) { case SelectedOperator.Addition: result = SimpleMath.Add(lastNumber, newNumber); break; case SelectedOperator.Multiplication: result = SimpleMath.Multiply(lastNumber, newNumber); break; case SelectedOperator.Division: result = SimpleMath.Divide(lastNumber, newNumber); break; case SelectedOperator.Substraction: result = SimpleMath.Substract(lastNumber, newNumber); break; } resultLabel.Content = result.ToString(); } }
private void equlButton_Click(object sender, RoutedEventArgs e) { double newNumber; bool divisionZero = false; newNumber = double.Parse(resultLabel.Content.ToString()); 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.Multiple(lastNumber, newNumber); break; case SelectedOperator.Division: if (newNumber != 0) { result = SimpleMath.Division(lastNumber, newNumber); } else { divisionZero = true; lastNumber = 0; } break; } if (divisionZero) { resultLabel.FontSize = 30; resultLabel.Content = "0 으로 나눌 수 없습니다."; } else { resultLabel.Content = result.ToString(); } }