开发者

Adding up chosen values from radio buttons

Hey guys, well I have figured out how to get the value from a radio button. but what I need to do now is add up all the selected amounts, so for example, chooses 1, then chooses 4. So the total will be 5, but then he chooses 3, so total is now 8.

This is the code I have to get the selected value:

        int valueinfo101 = 0;

    int count_int101 = 0;

            if (radioButton1.Checked)
        {
            valueinfo101 = 1;
        }

        else if (radioButton2.Checked)
        {
            valueinfo101 = 2;
        }

        else if (radioButton3.Checked)
        {
            valueinfo101 = 3;
        }

        else if (radioButton4.Checked)
        {
            valueinfo101 = 4;
        };

And then to show what they selected I wrote this:

            textBox1.Text = valueinfo101.ToString();

And then I wan开发者_运维技巧t to icrease count_int101 so I wrote this:

            count_int101++;

So what I want to be able to do now, is have a clear button, and choose again, but have it so that the choosen value adds onto the last one, so the first person chooses 3, clears the selected values, and the second person chooses 2, so the new totals 5. How do I get the total?


First, Why your radio buttons can be selected more than one?

Second, adding values is pretty simple if you already have a variable declared. So...

    int valueinfo101 = 0;

    int count_int101 = 0;

    if (radioButton1.Checked)
    {
        valueinfo101 = 1;
        count_int101 = count_int101 + 1;
    }

    else if (radioButton2.Checked)
    {
        valueinfo101 = 2;
        count_int101 = count_int101 + 2;
    }

    else if (radioButton3.Checked)
    {
        valueinfo101 = 3;
        count_int101 = count_int101 + 3;
    }

    else if (radioButton4.Checked)
    {
        valueinfo101 = 4;
        count_int101 = count_int101 + 4;
    };
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜