How to make output AND,NOT,OR,XOR

I want to make output AND,NOT,OR,XOR:
S = ++G * H < D > 100;
J = --G + D * H < 100;
K = ++S + --J * G > 200;
L = S + J + K > 150;
The question is: why the output is still the same even when I'm inputting different number.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
using namespace std;

int main()
{
    int S,J,K,L,G,H,D,AND,NOT,OR,XOR;
    cout << "Input G = "; cin >> G;
    cout << "Input H = "; cin >> H;
    cout << "Input D = "; cin >> D;
    S = ++G * H < D > 100;
    J = --G + D * H < 100;
    K = ++S + --J * G > 200;
    L = S + J + K > 150;
    AND = S && J && K && L;
    NOT = S + J + K + L;
    OR = S || J || K || L;
    XOR = (S != J != K != L);
    cout << "\n================| Output |================ ";
    cout << "\nOutput from S = ++G * H < D > 100 is   " << S;
    cout << "\nOutput from J = --G + D * H < 100 is   " << J;
    cout << "\nOutput from K = ++S + --J * G > 200 is " << K;
    cout << "\nOutput from L = S + J + K > 150; is    " << L;
    cout << "\nOutput from AND is " << AND;
    cout << "\nOutput from NOT is " << !NOT;
    cout << "\nOutput from OR is  " << OR;
    cout << "\nOutput from XOR is " << XOR;
    return 0;
}
Last edited on
Well first you need one of these, to understand precedence and associativity.
https://en.cppreference.com/w/cpp/language/operator_precedence

S = ++G * H < D > 100;
The result of the < is going to be either 0 or 1, and that is never going to be > 100.

See where this is going?
no i mean i understand the output is 0 and 1 but the output tho still the same even when i'm inputting different number, here's my output

Input G = 10
Input H = 55
Input D = 33

================| Output |================
Output from S = ++G * H < D > 100 is 1
Output from J = --G + D * H < 100 is -1
Output from K = ++S + --J * G > 200 is 0
Output from L = S + J + K > 150; is 0
Output from AND is 0
Output from NOT is 1
Output from OR is 1
Output from XOR is -2

-

Input G = 87
Input H = 33
Input D = 69

================| Output |================
Output from S = ++G * H < D > 100 is 1
Output from J = --G + D * H < 100 is -1
Output from K = ++S + --J * G > 200 is 0
Output from L = S + J + K > 150; is 0
Output from AND is 0
Output from NOT is 1
Output from OR is 1
Output from XOR is -2
Last edited on
What do you think this line is doing?
S = ++G * H < D > 100;

Please explain what you think that is doing, term by term, operation by operation, in the precise order.

Edit: Also, your XOR logic is bitwise, not logical. So that's why the output is not a 1 or a 0.
Logical XOR is just != (not equal) if you think about it.
Last edited on
wait i'm confused about that
S = ++G * H < D > 100;

sorry about XOR I'll take care of that.
Last edited on
Here's what I get when I compile by clicking on the "edit and run" link.
1
2
3
4
 In function 'int main()':
10:17: warning: comparisons like 'X<=Y<=Z' do not have their mathematical meaning [-Wparentheses]
17:14: warning: suggest parentheses around comparison in operand of '!=' [-Wparentheses]
17:19: warning: suggest parentheses around comparison in operand of '!=' [-Wparentheses]

No sane programmer writes expressions like that.
Mostly, they come from 2nd rate books and tutors attempting to look smart.
don't know man I'm doing my homework from my mentor the question is like this: Make logical operator AND,NOT,OR,XOR:
S = ++G * H < D > 100
J = --G + D * H < 100
K = ++S + --J * G > 200
L = S + J + K > 150
S will always be 0 as per salam's post above, so AND will always be 0. I suggest you work through the expressions using pen & paper as the computer would applying correct precedence.
> Make logical operator AND,NOT,OR,XOR:
What do you mean 'make'?

Are you trying to synthesize an AND operation (using only say arithmetic operators) without explicitly using the && operator?

What other 'hang a spoon off the end of your nose' nonsense is your 'mentor' pushing?
You're learning magic tricks, not programming.

TBH, we need to see the original full text of the assignment, because something just isn't right.
https://xyproblem.info/
Topic archived. No new replies allowed.