To check if a statement is 'Boolean true or boolean false'

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...
1
2
3

(x+z>=y)||(!(z==y)&&(z<x-2); Where x=1, y=1, z=1


Working...

(1+1>=1)||(!(1==1)&&(1<1-2)
(2>=1)||(!(1==1)&&(1<-1)
(true)||(false)&&(true)

Now I don't know what to do after this.
And how can I write this is as a code so the Computer can tell me the answer as true or false?


Hi,

It may sound silly but all you have to do is cout the statment

1
2
3
int x,y,z;
x=y=z=1;
cout<<(x+z>=y)||(!(z==y)&&(z<x-2));


this will do what you are trying to achieve

PS: 0 is false and 1 is true, so if you want to put true/false as your final output you could simply code it

PPS: you are missing a bracket (")") in your OP so please edit it...



Last edited on
PS: 0 is false and 1 is true, so if you want to put true/false as your final output you could simply code it

or use std::boolalpha

 
cout << boolalpha <<  (x+z>=y)||(!(z==y)&&(z<x-2));
Working...

(1+1>=1)||(!(1==1)&&(1<1-2)
(2>=1)||(!(1==1)&&(1<-1)
(true)||(false)&&(true)

Now I don't know what to do after this.

That doesn't look right to me, (1<-1) is false.

Working:
1
2
3
4
5
6
7
8
9
10
11
12
13
(x+z>=y)||(!(z==y)&&(z<x-2))

(1+1>=1)||(!(1==1)&&(1<1-2))

(2>=1)||(!(1==1)&&(1<-1))

true || (!true && false)

true || (false && false)

true || false

true
closed account (48T7M4Gy)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#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';
}

T F F
T
Program ended with exit code: 0
Last edited on
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';
}


true false false
true
Last edited on
wow! I didn't knew all that... thanks!!!
closed account (48T7M4Gy)
Well done - fixed
No problem, we all have moments like that.
THANK YOU ALL FOR YOUR SUPPORT !!!!!!!!!!!!!!!
GOD BLESS!
Topic archived. No new replies allowed.