The below statement is a boolean statement. I want to type this program below in Borland and see if the statement below statement is boolean false or boolean true...
#include <iostream>
int main()
{
int x = 1;
int y = 1;
int z = 1;
char a = (x+z >=y) ? 'T': 'F';
char b = !(z == y) ? 'T': 'F';
char c = z < x - 2 ? 'T': 'F';
char d = ( x+z >=y ) || ( !(z == y) && z < x - 2 ) ? 'T': 'F';
std::cout << a << ' ' << b << ' ' << c << '\n';
std::cout << d << '\n';
}
char 'T' and char 'F' will always evaluate as boolean true.
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13
#include <iostream>
int main()
{
char a = 'F';
char b = 'F';
char c = 'F';
char d = a || ( b && c ) ? 'T': 'F';
std::cout << a << ' ' << b << ' ' << c << '\n';
std::cout << d << '\n';
}
F F F
T
On the other hand, type bool is appropriate.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <iostream>
int main()
{
bool a = false;
bool b = false;
bool c = false;
bool d = a || ( b && c );
std::cout << std::boolalpha;
std::cout << a << ' ' << b << ' ' << c << '\n';
std::cout << d << '\n';
}
false false false
false
Hence,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <iostream>
int main()
{
int x = 1;
int y = 1;
int z = 1;
bool a = (x+z >=y);
bool b = !(z == y);
bool c = z < x - 2;
bool d = a || ( b && c );
std::cout << std::boolalpha;
std::cout << a << ' ' << b << ' ' << c << '\n';
std::cout << d << '\n';
}