I am absolute beginner in c^#.
One of my firs lessons were making a simple calculator, and i am having problem with some code in it.
To be precise with this part of code:
string theOperator;
private void btnPlus_Click(object sender, EventArgs e)
{
total1 = total1 + double.Parse(txtDisplay.Text);
txtDisplay.Clear();
theOperator = "+";
}
private void btnEquals_Click(object sender, EventArgs e)
{
switch (theOperator)
{
case "+":
total1 = total1 + double.Parse(txtDisplay.Text);
break;
case "-":
total1 = total1 - double.Parse(txtDisplay.Text);
break;
case "*":
total1 = total1 * double.Parse(txtDisplay.Text);
break;
case "/":
total1 = total1 / double.Parse(txtDisplay.Text);
break;
}
txtDisplay.Text = total2.ToString();
total1 = 0;
}
private void btnPoint_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnPoint.Text;
theOperator = ",";
}
private void btnMinus_Click(object sender, EventArgs e)
{
total1 = total1 + double.Parse(txtDisplay.Text);
txtDisplay.Clear();
theOperator = "-";
}
private void button2_Click(object sender, EventArgs e)
{
total1 = total1 + double.Parse(txtDisplay.Text);
txtDisplay.Clear();
theOperator = "*";
}
private void divideButton_Click(object sender, EventArgs e)
{
total1 = total1 + double.Parse(txtDisplay.Text);
txtDisplay.Clear();
theOperator = "/";
}
}
}
Thanks for help
Jonny111
One of my firs lessons were making a simple calculator, and i am having problem with some code in it.
To be precise with this part of code:
string theOperator;
private void btnPlus_Click(object sender, EventArgs e)
{
total1 = total1 + double.Parse(txtDisplay.Text);
txtDisplay.Clear();
theOperator = "+";
}
private void btnEquals_Click(object sender, EventArgs e)
{
switch (theOperator)
{
case "+":
total1 = total1 + double.Parse(txtDisplay.Text);
break;
case "-":
total1 = total1 - double.Parse(txtDisplay.Text);
break;
case "*":
total1 = total1 * double.Parse(txtDisplay.Text);
break;
case "/":
total1 = total1 / double.Parse(txtDisplay.Text);
break;
}
txtDisplay.Text = total2.ToString();
total1 = 0;
}
private void btnPoint_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnPoint.Text;
theOperator = ",";
}
private void btnMinus_Click(object sender, EventArgs e)
{
total1 = total1 + double.Parse(txtDisplay.Text);
txtDisplay.Clear();
theOperator = "-";
}
private void button2_Click(object sender, EventArgs e)
{
total1 = total1 + double.Parse(txtDisplay.Text);
txtDisplay.Clear();
theOperator = "*";
}
private void divideButton_Click(object sender, EventArgs e)
{
total1 = total1 + double.Parse(txtDisplay.Text);
txtDisplay.Clear();
theOperator = "/";
}
}
}
Thanks for help
Jonny111