How can I get a right value in label2 that when I click on the equal button at the second or more time? Please help.. I am stuck

private void button3_Click(object sender, EventArgs e)
        {
            if (label1.Text == "0" || isActivity == true) {
                label1.Text = ""; isActivity = false;
            }
            if (label1.Text.Length < 28)
                label1.Text += "9";
            else
                SystemSounds.Beep.Play();
        }
        private void button12_Click(object sender, EventArgs e)
        {
            //label2 is a label to keep all process  -and- isActivity is a boolean to apply operators whether pressed
            //result is decimal variable to keep data to compute
            //label1 is a label to keep values when click on numbers's button
            //op is a string variable to keep operators */-+
            if (label2.Text == "") {
                label2.Text = label1.Text + "+";
                result = Convert.ToDecimal(label1.Text);
                isActivity = true;
                op = "+";
            }
            else if (label2.Text.Contains("=")) {
                label2.Text += "+";
                isActivity = true;
                op = "+";
            }
            else  {
                label2.Text += label1.Text + "+";
                result += Convert.ToDecimal(label1.Text);
                label1.Text = result.ToString();
                isActivity = true;
            }
        }

Here is also a screen capture

Recommended Answers

All 3 Replies

create a public variable for your result (which is populated when you hit '=' ), clear it only when you hit Clear.. upon hitting '=' the second time, if the public var > 0, then do not reprocess the calculation

Thanks for your suggestion to make my code fix but I did like that finally.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.