What is the boolean value of each statement?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
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;
modoran wrote: |
---|
How about std::boolalpha in your cout statements ?
http://www.cplusplus.com/reference/ios/boolalpha/ |
Here you go!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
#include <iostream>
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