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.
#include <iostream>
usingnamespace 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;
}
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
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.
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]
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.