I have two ever evolving variables that I want to compare. Call them x and checksum. If the two variables are within 100 of one another for example, everything is fine. But if the margin is greater than 100 I would want it to throw up an error.

How would I go about writing this condition?

Thanks folks.

(x - checksum) must be less than 100 AND (x - checksum) must be greater than -100 (or you can use absolute value but this is much cheaper)

if ( ( x - checksum) <= 100)
puts ("a ok");
else
...

Naturally, thanks!

That's correct if you're using the absolute value abs(x - checksum) or unless you know for absolutely sure that x will always be greater than checksum. If not you need the && with the (x - checksum) > -100 as what if the relation between the two is flipped around.

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.