0

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.

2
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by Domtheripper
0

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

0

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.

0

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

Thanks for the post.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.