I am new to C# and have encountered a problem with the following if statement...

measurement = GetRandomInt(0, 2);
            measurement2 = GetRandomInt(0, 2);
   
            if ((measurement == 1) || (measurement2 == 1))
                q3correct = 1;
            else
                q3correct = 0;

The statement works around 80% of the time and i have checked every possible sequence of numbers several times. It seems to happen randomly but occasionally the variable is given the wrong value.

Thanks in advance.

There is nothing wrong with the code. If works exactly like it is supposed to. What makes you think it gives the wrong value?

It just does when running the code. I have 2 if statements like this in the code, on after the other. When given the same values, lets say 1 and 1 to both, q3correct and q4correct will have different values.

I have tried rearranging the statments but it still does this.

Worked out the problem now. Had some other code out of place further up.

Thanks for the post.

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.