Using relational operators in C++ -
am learning c++ programming , problem trying compare more 1 variables , not working. typed : if ( > b > c).
it doesn't work this, first expression a > b evaluates boolean, converted (because of comparison c) either 0 or 1, depending on truth value. attempt compare c, not want. use
if ( (a > b) && (b > c) ) instead. way compute logical and of 2 booleans, , if both true, mathematical statement a > b > c true (by transitivity).
if compile warnings on, compiler (probably) warn you. @ least g++ saying:
warning: comparisons 'x<=y<=z' not have mathematical meaning [-wparentheses]
Comments
Post a Comment