Wouldn't doing something like this be completely valid in C++? (The 45<rf<35 thing)Code:if (45<rf<35) { System.out.println("Bad right front tire pressure"); }
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?)
Results 1 to 5 of 5
Thread: Lolwut? (Java help?)
- 24 Nov. 2012 11:59pm #1
- Join Date
- Apr. 2010
- Location
- When freedom is outlawed only outlaws will be free
- Posts
- 5,113
- Reputation
- 195
- LCash
- 0.00
Lolwut? (Java help?)
- 25 Nov. 2012 08:30am #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.
- 25 Nov. 2012 10:53am #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.
Code:if (rf > 45 || rf < 35) {}
- 25 Nov. 2012 11:40am #4
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.
- 25 Nov. 2012 06:35pm #5
- Join Date
- Apr. 2010
- Location
- When freedom is outlawed only outlaws will be free
- Posts
- 5,113
- Reputation
- 195
- LCash
- 0.00