I'm trying to program a basic calculator and have gotten all the operations working. Yet my problem is getting the calculator to perform multiple operations without having to hit the equal button in between each seperate operation. I'm listing the operations, and equal button code along with the global variables I used. If any one could help it would be greatly appreciated. Thanks.
string operation ="";
bool newNum = false;
double numMemory;
bool decimalPushed =false;
void ButtonAddClick(object sender, System.EventArgs e)
{
operation ="+";
newNum = true;
numMemory = Convert.ToDouble(Display.Text);
}
void ButtonMultiplyClick(object sender, System.EventArgs e)
{
operation ="x";
newNum = true;
numMemory = Convert.ToDouble(Display.Text);
}
void ButtonDivideClick(object sender, System.EventArgs e)
{
operation ="/";
newNum = true;
numMemory = Convert.ToDouble(Display.Text);
}
void ButtonMinusClick(object sender, System.EventArgs e)
{
operation ="-";
newNum = true;
numMemory = Convert.ToDouble(Display.Text);
}
void ButtonEqClick(object sender, System.EventArgs e)
{
if (operation == "+")
{
if (newNum)
{
numMemory = Convert.ToDouble(Display.Text);
newNum = false;
}
double displayValue = Convert.ToDouble(Display.Text);
displayValue = numMemory + displayValue;
Display.Text = displayValue.ToString();
}
if (operation == "-")
{
if (newNum)
{
numMemory = Convert.ToDouble(Display.Text);
newNum = false;
}
double displayValue = Convert.ToDouble(Display.Text);
displayValue = numMemory - displayValue;
Display.Text = displayValue.ToString();
}
if (operation == "x")
{
if (newNum)
{
numMemory = Convert.ToDouble(Display.Text);
newNum = false;
}
double displayValue = Convert.ToDouble(Display.Text);
displayValue = numMemory * displayValue;
Display.Text = displayValue.ToString();
}
if (operation == "/")
{
if (newNum)
{
numMemory = Convert.ToDouble(Display.Text);
newNum = false;
}
double displayValue = Convert.ToDouble(Display.Text);
displayValue = numMemory / displayValue;
Display.Text = displayValue.ToString();
}
}