SparkFun Forums 

Where electronics enthusiasts find answers.

General project discussion / help
Did you make a robotic coffee pot which implements HTCPCP and decafs unauthorized users? Show it off here!
By alex.nev
hello evryone!
i`m a bit confused with the next thing. So i have x and y coords. I need do do an IF expression when both conditions are performed. Condition for X is when its in a range from 0,00 to 100,00 or over 230,00 and at the same time Y is in the range from 0,00 to 20,00 or over 180 then do {}

i`ve made it like

if (x<=100 || x>=230 && (y>=180 || y<20))


But you know its not working lika a charm...

Maybe there is a better solution for such logic like using an array? Im a newbie so don kick me too much))) Thanks guys!
By jremington
Take a look at logical operator precedence and then decide if you are using the parentheses correctly.

Hint: since you are treating X and Y differently, for the same basic logical test, the answer is no.
User avatar
By DanV
You need more parenthesis:

if (x<=100 || x>=230 && (y>=180 || y<20))

if ((x<=100) || ((x>=230) && ((y>=180) || (y<20))))

You must be very precise about what comparison is being done where - leave no doubt.
Don't count on operator precedence, just brute force it.
By jremington
You can, in fact, count on operator precedence. Guaranteed.

But most people don't bother to learn the rules that the compiler STRICTLY follows.
User avatar
By DanV
That's really what I was implying - don't count on what you may think you know about operator precedence.
long long title how many chars? lets see 123 ok more? yes 60

We have created lots of YouTube videos just so you can achieve [...]

Another post test yes yes yes or no, maybe ni? :-/

The best flat phpBB theme around. Period. Fine craftmanship and [...]

Do you need a super MOD? Well here it is. chew on this

All you need is right here. Content tag, SEO, listing, Pizza and spaghetti [...]

Lasagna on me this time ok? I got plenty of cash

this should be fantastic. but what about links,images, bbcodes etc etc? [...]