C# calculator project help

Sorry I meant 1/42 was the reciprocal. So my other event handlers are like so:

private void btnEquals_click(object sender, EventArgs e) { if (lblDisplay.Text != "") { double answer; num2 = Convert.ToDouble(lblDisplay.Text); if (opChosen == "add") { answer = num1 + num2; lblDisplay.Text = answer + ""; } else if ""and so on""

So what I have so far tried to get reciprocal working is this:

private void btnEquals_click(object sender, EventArgs e) { if (lblDisplay.Text != "") { double answer; num2 = Convert.ToDouble(lblDisplay.Text); if (opChosen == "add") { answer = num1 + num2; lblDisplay.Text = answer + ""; } else if (opChosen == "reciprocal") { answer = 1 / num1; lblDisplay.Text = answer + ""; } } }

private void btnReciprocal_click(object sender, EventArgs e) { if (lblDisplay.Text != "") { num1 = Convert.ToDouble(lblDisplay.Text); opChosen = "reciprocal"; lblDisplay.Text = ""; } }

It didnt do anything though, when I would enter 6 and hit the 1/x button the screen only went blank. I used the same formatting as I did with the other operations so I'm sure I'm missing something. The "answer = 1 / num1;" is probably it.

EDIT - If I added "num3 = 1;" to the top of the equals event handler will that allow me to do "answer = num3 / num1;" instead of num3 being entered as just "1"??

/r/learnprogramming Thread Parent