tags:

views:

42

answers:

1

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 want 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?

+1  A: 

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;
    };
Umair Ashraf
Well, the program I am trying to make is like a survey, one person selects what they think the rating is, then they hit the clear button, then onather person chooses a value they think it is worth, and so on. At the end I want to work out the average is well.
Codie Vincent
In the end I want to add up all the choosen values and divide by the count to get the average.
Codie Vincent
okay if that code works for you, please mark as answer.
Umair Ashraf
I dont see how that code would work for me, i could be wrong, but all count_int101 is doing is getting the exact number as valueinfo101
Codie Vincent
What I need is to have it so when the "go" button is pressed, and they select 4, it stores 4, then the form is cleared. The next person chooses 2, it "adds" 2 to "4", so now the stored "total" is now 6. At the moment with your script, when I clear the form, the count_int101 value get cleared too..
Codie Vincent