### True/False

What is the boolean value of each statement?

 ``123456789101112131415161718`` `````` int i = 4; int j = 3; bool true_false; true_false = (j<4); true_false = (j<3); true_false = (j< 1); true_false = (i< 4); true_false = (j <=4); true_false = (4> 4); true_false = (i != j); true_false = (i == j || < 100); true_false = ( i == j && i < 100 ); true_false = ( i < j || true_false && j >= 3); true_false = ( ! ( i > 2 && j == 4); true_false = !1; ``````
Last edited on
What is `'i'` and what is `'j'`?
int i = 4;
int j = 3;
bool true_false;
@Bolong Yu

You can easily find the answers to your program, by adding a cout, of the true_false assignments.

 ``123456789101112131415161718192021222324`` ``````#include using namespace std; int main() { int i = 4; int j = 3; bool true_false; true_false = (j<4);cout << true_false << endl; true_false = (j<4);cout << true_false << endl; true_false = (j<3);cout << true_false << endl; true_false = (j< 1);cout << true_false << endl; true_false = (i< 4);cout << true_false << endl; true_false = (j <=4);cout << true_false << endl; true_false = (4> 4);cout << true_false << endl; true_false = (i != j);cout << true_false << endl; true_false = (i == j || i < 100);cout << true_false << endl; true_false = ( i == j && i < 100 );cout << true_false << endl; // added the 'i' before <100 true_false = ( i < j || true_false && j >= 3);cout << true_false << endl; true_false = ( ! ( i > 2 && j == 4));cout << true_false << endl;// Needed another ) to balance parentheses true_false = !1;cout << true_false << endl; return 0; }``````
 ``123456789101112131415161718192021222324`` ``````#include using namespace std; int main() { int i = 4; int j = 3; bool true_false; true_false = (j<4);if(true_false==1){cout<<"true"< 4);if(true_false==1){cout<<"true"<= 3);if(true_false==1){cout<<"true"< 2 && j == 4));if(true_false==1){cout<<"true"<

Again, `whitenite` beat me to it, but I made the code a little more user-friendly.
How about `std::boolalpha` in your cout statements ?
http://www.cplusplus.com/reference/ios/boolalpha/
modoran wrote:
http://www.cplusplus.com/reference/ios/boolalpha/

Here you go!

 ``123456789101112131415161718192021222324`` ``````#include using namespace std; int main() { int i = 4; int j = 3; bool true_false; true_false = (j<4);cout << boolalpha << true_false << endl; true_false = (j<4);cout << boolalpha << true_false << endl; true_false = (j<3);cout << boolalpha << true_false << endl; true_false = (j< 1);cout << boolalpha << true_false << endl; true_false = (i< 4);cout << boolalpha << true_false << endl; true_false = (j <=4);cout << boolalpha << true_false << endl; true_false = (4> 4);cout << boolalpha << true_false << endl; true_false = (i != j);cout << boolalpha << true_false << endl; true_false = (i == j || i < 100);cout << boolalpha << true_false << endl; true_false = ( i == j && i < 100 );cout << boolalpha << true_false << endl; // added the 'i' before <100 true_false = ( i < j || true_false && j >= 3);cout << boolalpha << true_false << endl; true_false = ( ! ( i > 2 && j == 4));cout << boolalpha << true_false << endl;// Needed another ) to balance parentheses true_false = !1;cout << boolalpha << true_false << endl; return 0; }``````

That's something I was looking for. Thanks modoran!
Last edited on
Topic archived. No new replies allowed.