True/False
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;
@Bolong Yu
You can easily find the answers to your program, by adding a cout, of the true_false assignments.
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 << 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;
}
|
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);if(true_false==1){cout<<"true"<<endl;}else{cout<<"false"<<endl;}
true_false = (j<4);if(true_false==1){cout<<"true"<<endl;}else{cout<<"false"<<endl;}
true_false = (j<3);if(true_false==1){cout<<"true"<<endl;}else{cout<<"false"<<endl;}
true_false = (j< 1);if(true_false==1){cout<<"true"<<endl;}else{cout<<"false"<<endl;}
true_false = (i< 4);if(true_false==1){cout<<"true"<<endl;}else{cout<<"false"<<endl;}
true_false = (j <=4);if(true_false==1){cout<<"true"<<endl;}else{cout<<"false"<<endl;}
true_false = (4> 4);if(true_false==1){cout<<"true"<<endl;}else{cout<<"false"<<endl;}
true_false = (i != j);if(true_false==1){cout<<"true"<<endl;}else{cout<<"false"<<endl;}
true_false = (i == j || i < 100);if(true_false==1){cout<<"true"<<endl;}else{cout<<"false"<<endl;}
true_false = ( i == j && i < 100 );if(true_false==1){cout<<"true"<<endl;}else{cout<<"false"<<endl;} // added the 'i' before <100
true_false = ( i < j || true_false && j >= 3);if(true_false==1){cout<<"true"<<endl;}else{cout<<"false"<<endl;}
true_false = ( ! ( i > 2 && j == 4));if(true_false==1){cout<<"true"<<endl;}else{cout<<"false"<<endl;}// Needed another ) to balance parentheses
true_false = !1;if(true_false==1){cout<<"true"<<endl;}else{cout<<"false"<<endl;}
return 0;
}
|
Again,
whitenite beat me to it, but I made the code a little more user-friendly.
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
Topic archived. No new replies allowed.