Home > Mobile >  Having some trouble with my equals button
Having some trouble with my equals button

Time:04-18

this is the first real program I'm making for school, and I'm having some trouble with it. I believe my case structure and everything else is right, but when I attempt to add two numbers in my calculator, the text property for label 7 does not update.

This is my sample of how I have my case structure set up:

    private void radioButton5_CheckedChanged(object sender, EventArgs e)
    {
        if (radioButton5.Checked == true)
            rb = 5;
    }

and then the actual case structure itself, as well as the rest of the code:

    public void button1_Click(object sender, EventArgs e)
    {
        double num1 = 0;
        double num2 = 0;
        double result = 0;
        string resultInLabel;

        switch (rb)
        {
            case 1:
                result = num1   num2;
                break;
            case 2:
                result = num1 - num2;
                break;
            case 3:
                result = num1 * num2;
                break;
            case 4:
                result = num1 / num2;
                break;
            case 5:
                break;
        }
        resultInLabel = Convert.ToString(result);
        resultInLabel = label7.Text;
    }

button1 is my equals button, forgot to rename it. If more code is needed please let me know, first time posting and unsure how much more context is needed. Thanks for any answers.

CodePudding user response:

If you want to change the text of the label you have to assign a value to it, not read its current value. Make your last line the following:

label7.Text = resultInLabel;
  •  Tags:  
  • c#
  • Related