Check if value is in certain range, and consider overflow

Hey folks,

Lets say that I am heading North when the direction of my movement is somewhere between 340, and 20 degrees, thus accepting N to be +-20 degrees from the actual North direction of 0. So if my direction is a random number X between 0 and 359, how am I going to determine if my variable X is in the provided range?

Thank you!

Turn the question in its head

If the random number (0 to 359) is greater than 20 and less than 340 then it is not in the required range, otherwise it is

1 Like

Hey Heli,

Thank you very much, again!

Or, turning it back on its feet:

If the random number is greater than 340 or less than 20 then it is North.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.