Output append with input in C# - c#

I am creating a Calculator in C# windows form and after performing operation(+,-,*,/) the output of the operation append with the input of the next operation!
This is the result of adding 33 in 33
After pressing equal its gets 66 and when further input such as 33 is added input is appended to previous output
This is the code i have written so far..
public Calculator()
{
InitializeComponent();
}
private void btn_click(object sender, EventArgs e)
{
if (( txtResult.Text == "0")||(operation_pressed))
txtResult.Clear();
Button b = (Button)sender;
txtResult.Text = txtResult.Text + b.Text;
operation_pressed = false;
}
private void btnPoint_Click(object sender, EventArgs e)
{
Button b = (Button)sender;
if (b.Text == ".")
{
if (!txtResult.Text.Contains("."))
{
txtResult.Text = txtResult.Text + b.Text;
}
}
else
{
txtResult.Text = txtResult.Text + b.Text;
}
}
private void operator_click(object sender, EventArgs e)
{
Button b = (Button)sender;
operation = b.Text;
value = Double.Parse(txtResult.Text);
operation_pressed = true;
}
private void btnClear_Click(object sender, EventArgs e)
{
txtResult.Text = "0";
}
private void btnC_Click(object sender, EventArgs e)
{
txtResult.Clear();
value = 0d;
}
private void btnEqual_Click(object sender, EventArgs e)
{
switch (operation)
{
case "+":
txtResult.Text = (value + Double.Parse(txtResult.Text)).ToString();
break;
case "-":
txtResult.Text = (value - Double.Parse(txtResult.Text)).ToString();
break;
case "*":
txtResult.Text = (value * Double.Parse(txtResult.Text)).ToString();
break;
case "/":
txtResult.Text = (value / Double.Parse(txtResult.Text)).ToString();
break;
default:
break;
}
operation_pressed = false;
operation = "";
}

The text is appending to the existing value because of this line in the btn_click event
txtResult.Text = txtResult.Text + b.Text;
Earlier in this event, you are checking the value of operation_pressed before calling txtResult.Clear();, however you are setting this to false in the btnEqual_Click event.
Removing that line so that operation_pressed remains true after = is pressed would then clear the result on next button press.
On a side note, you will be better off storing the value in a variable, rather than parsing txtResult to double each time.

Related

how to bind keyboard numbers with a calculator app that i created?

Hi I have created a window calculator and it is working fine however, i want to be able to use my keyboard numbers as well for my calculator app . what do i do? here is my code
public partial class Form1 : Form
{
Double resultValue = 0;
String operationPerformed = "";
bool isOperationPerformed = false;
public Form1()
{
InitializeComponent();
}
private void button_click(object sender, EventArgs e)
{
if ((textBox_Result.Text == "0") || (isOperationPerformed))
textBox_Result.Clear();
isOperationPerformed = false;
Button button = (Button)sender;
if (button.Text == ".")
{
if (!textBox_Result.Text.Contains("."))
textBox_Result.Text = textBox_Result.Text + button.Text;
} else
textBox_Result.Text = textBox_Result.Text + button.Text;
}
private void operator_click(object sender, EventArgs e)
{
Button button = (Button)sender;
if (resultValue != 0)
{
EqualsToBtn.PerformClick();
operationPerformed = button.Text;
labelCurrentOperation.Text = resultValue + " " + operationPerformed;
isOperationPerformed = true;
}else
{
operationPerformed = button.Text;
resultValue = Double.Parse(textBox_Result.Text);
labelCurrentOperation.Text = resultValue + " " + operationPerformed;
isOperationPerformed = true;
}
}
private void RefreshBtn_Click(object sender, EventArgs e)
{
textBox_Result.Text = "0";
}
private void CancelBtn_Click_1(object sender, EventArgs e)
{
textBox_Result.Text = "0";
resultValue = 0;
}
private void EqualsToBtn_Click_1(object sender, EventArgs e)
{
switch (operationPerformed)
{
case "+":
textBox_Result.Text = (resultValue + Double.Parse(textBox_Result.Text)).ToString();
break;
case "-":
textBox_Result.Text = (resultValue - Double.Parse(textBox_Result.Text)).ToString();
break;
case "*":
textBox_Result.Text = (resultValue * Double.Parse(textBox_Result.Text)).ToString();
break;
case "/":
textBox_Result.Text = (resultValue / Double.Parse(textBox_Result.Text)).ToString();
break;
}
resultValue = Double.Parse(textBox_Result.Text);
labelCurrentOperation.Text = "";
}
}
}
You can achieve it by subscribing to KeyDown event.
Fisrt, need to set KeyPreview to true.
public Form1()
{
InitializeComponent();
KeyPreview = true;
}
Then use swicth to judge which key pressed. Keys Enum
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.NumPad0:
case Keys.D0:
// Zero
buttonnum0.PerformClick(); // simulate pressing buttonnum0
break;
case Keys.NumPad1:
case Keys.D1:
// One
buttonnum1.PerformClick();
break;
// ... etc
case Keys.Oemplus:
case Keys.Add:
// Plus
buttonplus.PerformClick();
break;
default:
return;
}
e.Handled = true;
}
You can use the processcmdkey
protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
if (keyData == ( Keys.Numpad0 | Keys.Numpad0)) { // just an example, handle the rest as you need
doSomething();
return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}

When I put two or more operators in eg '*' and error occurs, feel free to edit code

Operation error when two operations are clicked, i want error handling to take place so i cant put multiple * in a row
namespace Calculator_Assignment
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
float num, ans;
int count;
private void Form1_Load(object sender, EventArgs e)
{
}
private void Button_click(object sender, EventArgs e)
{
Button button = (Button)sender; //adds the numbers into the screen when clicked
Screen.Text = Screen.Text + button.Text;
Screen.ForeColor = Color.Red; //text that entered appears red
}
private void operatorclick(object sender, EventArgs e)
{
Button button = (Button)sender; //adds the symbols into the screen when clicked
Screen.Text = Screen.Text + button.Text; //all symbols are under button_click so i do not have to repeat the code over/
}
private void Clearclick(object sender, EventArgs e)
{
Screen.Clear(); //when clicked clears the screen
Result.Clear(); //when clicked clears the result
}
private void Decimalclick(object sender, EventArgs e)
{
Screen.Text = Screen.Text + "."; //adds decimal point to screen when/if clicked
Screen.ForeColor = Color.Red; //decimal point appears red
}
private void Closebtn_Click(object sender, EventArgs e)
{
this.Close(); // closes the application down
}
private void plusclick(object sender, EventArgs e) //addition
{
num = float.Parse(Screen.Text);
Screen.Clear(); //clears the screen of everything
Screen.Focus(); //textbox is focused upon when the screen is cleared
count = 1; //this counts the store case
Screen.Text = num.ToString() + "+"; //this puts the text onto the top text box
}
private void multiplyclick(object sender, EventArgs e) //multiply
{
num = float.Parse(Screen.Text);
Screen.Clear(); //clears the screen of everything
Screen.Focus(); //textbox is focused upon when the screen is cleared
count = 3; //this counts the store case
Result.Text = num.ToString() + "*"; //this puts the text onto the top textbox
}
private void divideclick(object sender, EventArgs e) //divide
{
num = float.Parse(Screen.Text);
Screen.Clear(); //clears the screen of everything
Screen.Focus(); //textbox is focused upon when the screen is cleared
count = 4; //this counts the store case
Screen.Text = num.ToString() + "/"; //this puts the text onto the
}
private void subtractclick(object sender, EventArgs e) //subtract
{
num = float.Parse(Screen.Text);
Screen.Clear(); //clears the screen of everything
Screen.Focus(); //textbox is focused upon when the screen is cleared
count = 2; //this counts the store case
Result.Text = num.ToString() + "-"; //this puts the text onto the label
}
private void equalsclick(object sender, EventArgs e)
{
switch (count) //initalising switch statement
{
case 1:
ans = num + float.Parse(Screen.Text);//Adding numbers
Result.Text = ans.ToString(); //this converts my answer from a float to a string
break;
case 2:
ans = num - float.Parse(Screen.Text); //Subtracting numbers
Result.Text = ans.ToString(); //float to a string
break;
case 3:
ans = num * float.Parse(Screen.Text); //Multiplying numbers
Result.Text = ans.ToString(); //float to a string
break;
case 4:
ans = num / float.Parse(Screen.Text); //Division of numbers
Result.Text = ans.ToString(); //float to a string
break;
default: //the default figure
break;
}
}
}
}
Quick solution:
Create a method called void AppendOperator(string operator)
This method should check the previous character before appending it. If the previous character is an operator then simply return.
Call this new method in place of all the locations where you assign a value to Result.Text
AppendOperator implementation example:
private readonly HashSet<char> _operators = new HashSet<char>() { '+', '*', '-', '/' };
void AppendOperator(string operation)
{
char lastChar = Result.Text.LastOrDefault();
if (_operators.Contains(lastChar)) return;
Result.Text = num.ToString() + operation;
}

Double result when using keypress

I made this calculator in C# and I have one problem: When I press keyboard something like 1 it gives me incorrect result double number. I don't get the correct result.
Do you know what I am doing wrong,
Thank you very much!
namespace Calculator
{
public partial class Calculator : Form
{
Double value = 0;
String operation = "";
int i = 0;
bool operation_pressed = false;
bool button_dot = false;
OperationClass class1 = new OperationClass();
public Calculator()
{
InitializeComponent();
this.KeyPreview = true;
this.KeyPress += new KeyPressEventHandler(Calculator_KeyPress);
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void Calculator_Load(object sender, EventArgs e)
{
}
private void Calculator_KeyPress(object sender, KeyPressEventArgs e)
{
if ((result.Text == "0") || (operation_pressed))
result.Clear();
switch (e.KeyChar)
{
// key press from 0-9
case (char)48:
case (char)49:
case (char)50:
case (char)51:
case (char)52:
case (char)53:
case (char)54:
case (char)55:
case (char)56:
case (char)57:
e.Handled = true;
result.Text += e.KeyChar.ToString();
break;
}
}
private void button_Click(object sender, EventArgs e)
{
if ((result.Text == "0") || (operation_pressed))
result.Clear();
operation_pressed = false;
Button b = (Button)sender;
result.Text = result.Text + b.Text;
}
private void operator_click(object sender, EventArgs e)
{
Button b = (Button)sender;
operation = b.Text;
value = Double.Parse(result.Text);
operation_pressed = true;
equation.Text = value + " " + operation;
}
private void buttonCE_Click(object sender, EventArgs e)
{
result.Text = "0";
equation.Text = "";
button_dot = false;
}
private void buttonC_Click(object sender, EventArgs e)
{
result.Clear();
value = 0;
}
private void buttonEqual_Click(object sender, EventArgs e)
{
equation.Text = "";
button_dot = false;
operation_pressed = true;
if (operation != "")
result.Text = class1.GetResult(operation, value, result.Text);
else
result.Text = result.Text + "";
}
private void buttonDot_Click(object sender, EventArgs e)
{
Button b = (Button)sender;
if ((!button_dot && !operation_pressed) || result.Text == "0")
result.Text = result.Text + b.Text;
button_dot = true;
}
}
}
You don't need to append keychar in your result.Text (Assuming result is your TextBox item) as you have written in line result.Text += e.KeyChar.ToString();. That's the line which is doubling your input.
Remove it and it'll work as expected.
I'd change it from keypress to KeyUp instead. That way it only fires as soon as the key is released.
Edit: Check out this info: Difference between the KeyDown Event, KeyPress Event and KeyUp Event in Visual Studio

windows forms input continuously showing

I cannot for the life of me figure out how to continuously show the input and then output of the numbers for this.
What do you do to store the numbers somewhere and then show them? I've gone in so many circles that I have confused myself to oblivion.
I know what needs to be done but not how or exactly where to do it?
public partial class Form1 : Form
{
char c;
double num1;
double num2;
public Form1()
{
InitializeComponent();
}
private void btn0_Click(object sender, EventArgs e)
{
txtBox.Text += 0;
}
private void btn1_Click(object sender, EventArgs e)
{
txtBox.Text += 1;
}
private void btn2_Click(object sender, EventArgs e)
{
txtBox.Text += 2;
}
private void btn3_Click(object sender, EventArgs e)
{
txtBox.Text += 3;
}
private void btn4_Click(object sender, EventArgs e)
{
txtBox.Text += 4;
}
private void btn5_Click(object sender, EventArgs e)
{
txtBox.Text += 5;
}
private void btn6_Click(object sender, EventArgs e)
{
txtBox.Text += 6;
}
private void btn7_Click(object sender, EventArgs e)
{
txtBox.Text += 7;
}
private void btn8_Click(object sender, EventArgs e)
{
txtBox.Text += 8;
}
private void btn9_Click(object sender, EventArgs e)
{
txtBox.Text += 9;
}
private void btnDecimal_Click(object sender, EventArgs e)
{
if (!txtBox.Text.Contains('.'))
txtBox.Text += '.';
}
private void btnAddition_Click(object sender, EventArgs e)
{
c = '+';
num1 = double.Parse(txtBox.Text);
txtBox.Text = string.Empty;
}
private void btnSubtraction_Click(object sender, EventArgs e)
{
c = '-';
num1 = double.Parse(txtBox.Text);
txtBox.Text = string.Empty;
}
private void btnMultiplication_Click(object sender, EventArgs e)
{
c = '*';
num1 = double.Parse(txtBox.Text);
txtBox.Text = string.Empty;
}
private void btnDivision_Click(object sender, EventArgs e)
{
c = '/';
num1 = double.Parse(txtBox.Text);
txtBox.Text = string.Empty;
}
private void btnClear_Click(object sender, EventArgs e)
{
txtBox.Clear();
}
private void btnEqual_Click(object sender, EventArgs e)
{
num2 = double.Parse(txtBox.Text);
double result;
switch (c)
{
case '+':
result = num1 + num2;
txtBox.Text = result.ToString();
break;
case '-':
result = num1 - num2;
txtBox.Text = result.ToString();
break;
case '/':
if (num2 != 0)
{
result = num1 / num2;
txtBox.Text = result.ToString();
}
else
{
txtBox.Text = "You can't divide by zero... sign up for Math 100 please =)";
}
break;
case '*':
result = num1 * num2;
txtBox.Text = result.ToString();
break;
}
}
}
}
I'll let you wire this up, but here is what I threw together.
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private string op;
private string num1;
private string num2;
private void handleNumberButtonClick(object sender, System.EventArgs e)
{
var num = Convert.ToInt16(((Button)sender).Tag);
if (op == null)
num1 += num;
else
num2 += num;
PrintEquation(num1, op, num2);
}
private void PrintEquation(string first, string oper = null, string second = null, string equals = null, string result = null)
{
txtBox.Text = first + oper + second + equals + result;
}
private void handleOperatorButtonClick(object sender, System.EventArgs e)
{
op = ((Button)sender).Tag.ToString();
PrintEquation(num1, op);
}
private void btnDecimal_Click(object sender, EventArgs e)
{
if (op == null && !num1.Contains(".")) num1 += ".";
if (op != null && !num2.Contains(".")) num2 += ".";
this.PrintEquation(num1, op, num2);
}
private void btnClear_Click(object sender, EventArgs e)
{
txtBox.Clear();
op = null;
num1 = null;
num2 = null;
}
private void btnEqual_Click(object sender, EventArgs e)
{
double result = 0;
var first = Convert.ToDouble(num1);
var second = Convert.ToDouble(num2);
switch (op)
{
case "+":
result = first + second;
break;
case "-":
result = first - second;
break;
case "/":
if (second != 0)
{
result = first / second;
}
else
{
errorLbl.Text = "You can't divide by zero... sign up for Math 100 please =)";
}
break;
case "*":
result = first * second;
break;
}
this.PrintEquation(num1, op, num2, "=", result.ToString());
}
}
To give you a clue on how things go together, this is what the button should look like in the .designer.cs file:
this.btn0.Location = new System.Drawing.Point(12, 60);
this.btn0.Name = "btn0";
this.btn0.Size = new System.Drawing.Size(75, 23);
this.btn0.TabIndex = 1;
this.btn0.Tag = "0";
this.btn0.Text = "btn0";
this.btn0.UseVisualStyleBackColor = true;
this.btn0.Click += new System.EventHandler(this.handleNumberButtonClick);
Notice the .Tag value and the eventhandler.
The Operators should look like this(this is add, notice the tag and the Click Event handler):
this.addButton.Location = new System.Drawing.Point(178, 60);
this.addButton.Name = "addButton";
this.addButton.Size = new System.Drawing.Size(75, 23);
this.addButton.TabIndex = 11;
this.addButton.Tag = "+";
this.addButton.Text = "add";
this.addButton.UseVisualStyleBackColor = true;
this.addButton.Click += new System.EventHandler(this.handleOperatorButtonClick);
And the decimal, like this:
this.button4.Location = new System.Drawing.Point(178, 176);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(75, 23);
this.button4.TabIndex = 15;
this.button4.Tag = ".";
this.button4.Text = "decimal";
this.button4.UseVisualStyleBackColor = true;
this.button4.Click += new System.EventHandler(this.btnDecimal_Click);
Oh, and throw this in your clear button definition
this.button5.Click += new System.EventHandler(this.btnClear_Click);
Special thanks to #Mark Hall and #Martin James for their insights

C# Calculator - textBox to listBox

This calculator is extremely basic and so I'm only working with two values to calculate at a time.
I am calculating two values only val1 and val2. These values can be of any size including a decimal point.
I have buttons for numbers 0-9, a decimal point, plus, minus, divide, multiply and equals.
I want val1, val2 and the operator(ex. +,-,/,*) I choose to calculate these values to appear in my listBox after I hit the = button. Every calculation I make I want it added to the listBox underneath the previous calculation. When the listBox grows to a certain amount of calculations (10-15ish) I want the oldest calculation removed from the bottom and the newest added to the top of the list.
public partial class Form1 : Form
{
// global variables
bool plus = false;
bool minus = false;
bool multiply = false;
bool divide = false;
bool equal = false;
public Form1()
{
InitializeComponent();
} // **MUST HAVE**
private void button0_Click(object sender, EventArgs e)
{
CheckIfEqual();
textBox1.Text = textBox1.Text + "0";
} // makes number click usable
private void CheckIfEqual()
{
if (equal) // checks if equal is true
{
textBox1.Text = ""; // clear textBox
equal = false; // tells program there is new calculation
}
}
private void button1_Click(object sender, EventArgs e)
{
CheckIfEqual();
textBox1.Text = textBox1.Text + "1";
} // makes number click usable
private void button2_Click(object sender, EventArgs e)
{
CheckIfEqual();
textBox1.Text = textBox1.Text + "2";
} // makes number click usable
private void button3_Click(object sender, EventArgs e)
{
CheckIfEqual();
textBox1.Text = textBox1.Text + "3";
} // makes number click usable
private void button4_Click(object sender, EventArgs e)
{
CheckIfEqual();
textBox1.Text = textBox1.Text + "4";
} // makes number click usable
private void button5_Click(object sender, EventArgs e)
{
CheckIfEqual();
textBox1.Text = textBox1.Text + "5";
} // makes number click usable
private void button6_Click(object sender, EventArgs e)
{
CheckIfEqual();
textBox1.Text = textBox1.Text + "6";
} // makes number click usable
private void button7_Click(object sender, EventArgs e)
{
CheckIfEqual();
textBox1.Text = textBox1.Text + "7";
} // makes number click usable
private void button8_Click(object sender, EventArgs e)
{
CheckIfEqual();
textBox1.Text = textBox1.Text + "8";
} // makes number click usable
private void button9_Click(object sender, EventArgs e)
{
CheckIfEqual();
textBox1.Text = textBox1.Text + "9";
} // makes number click usable
private void buttonDecimal_Click(object sender, EventArgs e)
{
CheckIfEqual();
if (textBox1.Text.Contains("."))
{
return;
} // if it contains a decimal execute
else
{
textBox1.Text = textBox1.Text + ".";
} // adds decimal
} // end decimal
private void buttonPlusMinus_Click(object sender, EventArgs e)
{
if (textBox1.Text.Contains("-"))
{
textBox1.Text = textBox1.Text.Remove(0, 1);
} // if it contains the - character remove it
else
{
textBox1.Text = "-" + textBox1.Text;
} //
} // adds/removes -
private void buttonPlus_Click(object sender, EventArgs e)
{
if (textBox1.Text == "")
{
return;
} // if textbox is empty return
else
{
plus = true;
textBox1.Tag = textBox1.Text; // stores number
textBox1.Text = ""; // clears textbox
} // tells program we are adding
} // end plus
private void buttonMinus_Click(object sender, EventArgs e)
{
if (textBox1.Text == "")
{
return;
} // if textbox is empty return
else
{
minus = true;
textBox1.Tag = textBox1.Text; // stores number
textBox1.Text = ""; // clears textbox
} // tells program we are subtracting
}
private void buttonMultiply_Click(object sender, EventArgs e)
{
if (textBox1.Text == "")
{
return;
} // if textbox is empty return
else
{
multiply = true;
textBox1.Tag = textBox1.Text; // stores number
textBox1.Text = ""; // clears textbox
} // tells program we are multiplying
}
private void buttonDivide_Click(object sender, EventArgs e)
{
if (textBox1.Text == "")
{
return;
} // if textbox is empty return
else
{
divide = true;
textBox1.Tag = textBox1.Text; // stores number
textBox1.Text = ""; // clears textbox
} // tells program we are dividing
}
private void buttonEquals_Click(object sender, EventArgs e)
{
equal = true; // tells program it made a calculation
if (plus) // if true execute
{
decimal dec = Convert.ToDecimal(textBox1.Tag) + Convert.ToDecimal(textBox1.Text);
textBox1.Text = dec.ToString(); // display value once add is finished
plus = false;
} // end if plus
if (minus) // if true execute
{
decimal dec = Convert.ToDecimal(textBox1.Tag) - Convert.ToDecimal(textBox1.Text);
textBox1.Text = dec.ToString(); // display value once add is finished
minus = false;
} // end if minus
if (multiply) // if true execute
{
decimal dec = Convert.ToDecimal(textBox1.Tag) * Convert.ToDecimal(textBox1.Text);
textBox1.Text = dec.ToString(); // display value once add is finished
multiply = false;
} // end if multiply
try
{
if (divide) // if true execute
{
decimal dec = Convert.ToDecimal(textBox1.Tag) / Convert.ToDecimal(textBox1.Text);
textBox1.Text = dec.ToString(); // display value once add is finished
divide = false;
} // end if divide
} // try
catch (DivideByZeroException ex)
{
MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK);
} // catch
} // end buttonEquals
private void buttonClear_Click(object sender, EventArgs e)
{
plus = minus = multiply = divide = false; // makes all false regardless
textBox1.Text = ""; // clear
textBox1.Tag = ""; // clears
}
} // end partial class Form1
}// end namespace
Refactoring would be nice...
For example, you can use the same method for all your "numeric button click" event.
instead of
private void button1_Click(object sender, EventArgs e)
{
CheckIfEqual();
textBox1.Text = textBox1.Text + "1";
} // makes number click usable
...
private void button9_Click(object sender, EventArgs e)
{
CheckIfEqual();
textBox1.Text = textBox1.Text + "9";
} // makes number click usable
just use one method.
button1.Click += NumericButtonClick;
...
button9.Click +=NumericButtonClick;
private void NumericButtonClick(object sender, EventArgs e) {
CheckIfEqual();
textBox1.Text = textBox1.Text + ((Button)sender).Text;
}
Anyway.
Say you have a ListBox historyListBox;
Then just add a method
private void PopulateListBox(string left, string right, string operator) {
var newContent = string.Format("{0} {1} {2}", left, operator, right);
if (historyListBox.Items.Count == 15)
historyListBox.Items.RemoveAt(14);//
historyListBox.Items.Insert(0, newContent);
}
and then you could change the "equal_click event" (which sould be also refactored, but that's another problem)
private void buttonEquals_Click(object sender, EventArgs e)
{
var left = textBox1.Tag;
var right = textBox1.Text;
var operator = string.Empty;
equal = true; // tells program it made a calculation
if (plus) // if true execute
{
operator = "+";
decimal dec = Convert.ToDecimal(left) + Convert.ToDecimal(right);
textBox1.Text = dec.ToString(); // display value once add is finished
plus = false;
} // end if plus
if (minus) // if true execute
{
operator = "-";
decimal dec = Convert.ToDecimal(left) - Convert.ToDecimal(right);
textBox1.Text = dec.ToString(); // display value once add is finished
minus = false;
} // end if minus
//...etc
PopulateListBox(left, right, operator);
}

Categories