A preserved archive of the Logical Gamers community forums, 2009-2025. The original threads and posts, served read-only. Registration, posting and private messages are gone for good.

Lolwut? (Java help?)

1k views · started by 323 ·
#1
Lolwut? (Java help?)
if (45<rf<35)
{
System.out.println("Bad right front tire pressure");
}


Wouldn't doing something like this be completely valid in C++? (The 45<rf<35 thing)

All it's giving me in Java is errors.

What's a simple workaround that doesn't take another if statement? I couldn't think of any.

Thanks!

(The 45<rf<35 would mean "if rf is greater than 45 or less than thirty five")
(Oh wait, could I just use an or (||) for that?)
#2
IF (35 > rf) AND (rf > 45) [then] {...}

What you're looking for is something like that. What you originally put isn't a valid expression in most languages. What you were referring to in C++ is the ternary operator which is not a valid avenue or method in this case because it's basically just a short circuit if-then-else statement.

There may be other solutions but this should suffice.[/then]
#3
Is that really valid in c++? That has fairly poor readability. When I see that I just think of the mathematical expression a < x < b which means if x is between a and b.

Also, what Unintelligible posted will never evaluate to true. Use the OR (||) operator.

if (rf > 45 || rf < 35) {}
#4
Artificial wrote:
Is that really valid in c++? That has fairly poor readability. When I see that I just think of the mathematical expression a < x < b which means if x is between a and b.

Also, what Unintelligible posted will never evaluate to true. Use the OR (||) operator.

if (rf > 45 || rf < 35) {}


Bah. Just noticed why. AND definitely seemed more logical than using the ternary operator (linguistically so rather than mathematically which is the way I should have been looking at it). Did not test or give it more than a second's worth of thought. All I know is that 'a > b > c' isn't valid in C++ or any other languages I've used as far as I'm aware.
#5
Artificial wrote:
Is that really valid in c++? That has fairly poor readability. When I see that I just think of the mathematical expression a < x < b which means if x is between a and b.

Also, what Unintelligible posted will never evaluate to true. Use the OR (||) operator.

if (rf > 45 || rf < 35) {}


Well the thing you said, if x is between a and b, could be useful to me too. Like, if rf is between 35 and 45 it's good, instead of bad. Thanks for the help everyone.