public Double calculate() { Double x1 = 0; if (leftNode != null) { x1 = leftNode.calculate(); } Double x2 = 0; if (rightNode != null) { x2 = rightNode.calculate(); } switch (value) { case "+": calculatedValue = x1 + x2; return(calculatedValue); case "-": calculatedValue = x1 - x2; return(calculatedValue); case "*": calculatedValue = x1 * x2; return(calculatedValue); case "/": if (x2 == 0) { throw new Exception("Zero Division"); } calculatedValue = x1 / x2; return(calculatedValue); } calculatedValue = double11ToDouble(value); return(calculatedValue); }
private void Button_Click(object sender, EventArgs e) { if (update) { taskTextBox.Text = ""; resultTextBox.Text = ""; update = false; } switch (((Button)sender).Name) { case "clearButton": taskTextBox.Text = ""; resultTextBox.Text = ""; break; case "deleteButton": if (taskTextBox.Text.Length > 0) { taskTextBox.Text = taskTextBox.Text.Remove(taskTextBox.Text.Length - 1); } break; case "buttonNumber0": taskTextBox.Text += "0"; break; case "buttonNumber1": taskTextBox.Text += "1"; break; case "buttonNumber2": taskTextBox.Text += "2"; break; case "buttonNumber3": taskTextBox.Text += "3"; break; case "buttonNumber4": taskTextBox.Text += "4"; break; case "buttonNumber5": taskTextBox.Text += "5"; break; case "buttonNumber6": taskTextBox.Text += "6"; break; case "buttonNumber7": taskTextBox.Text += "7"; break; case "buttonNumber8": taskTextBox.Text += "8"; break; case "buttonNumber9": taskTextBox.Text += "9"; break; case "buttonNumberA": taskTextBox.Text += "A"; break; case "leftBracketButton": taskTextBox.Text += "("; break; case "rightBracketButton": taskTextBox.Text += ")"; break; case "multiplicationButton": taskTextBox.Text += "*"; break; case "divisionButton": taskTextBox.Text += "/"; break; case "additionButton": taskTextBox.Text += "+"; break; case "subtractionButton": taskTextBox.Text += "-"; break; case "dotButton": taskTextBox.Text += "."; break; case "resultButton": try { CalculateTree calc = new CalculateTree(taskTextBox.Text); calc.calculate(); resultTextBox.Text = calc.getResult(); } catch (Exception exep) { resultTextBox.Text = exep.Message; } update = true; break; } }