Thread: struggeling with an if statment clause

1. struggeling with an if statment clause

ill try to explain the clauses for it to be true

x can be 1 or -1 but has to be one of those 2
y has to be 1 if king is false or y can be 1 or -1 if king is true
Code:
```
x=1 | x=-1 | y=1 | y=-1 | king true | king false | desired result
____|______|_____|______|___________|____________|_________________
0 |  1   |  0  |  1   |    0      |    1       |   0
0 |  1   |  1  |  0   |    0      |    1       |   1
1 |  0   |  0  |  1   |    0      |    1       |   0
1 |  0   |  1  |  0   |    0      |    1       |   1
0 |  1   |  0  |  1   |    1      |    0       |   1
0 |  1   |  1  |  0   |    1      |    0       |   1
1 |  0   |  0  |  1   |    1      |    0       |   1
1 |  0   |  1  |  0   |    1      |    0       |   1```
hopefully the truth table will come out ok
coop

2. i have tried
Code:
`if (((x == -1 || x == 1) && (y == 1 || y ==-1) && king == true) || ((x == -1 || x== 1) && y == 1))`
but it always was true regardless of y and the king
coop

3. I would focus on the two result=0 cases.

This is true, regardless of the state of x/y
if ( king == 1 ) result = 1;

Also
if ( !king && ( (x==-1 && y==-1) || (x == 1 && y== -1) ) ) result = false;

4. This is not a truth map.... I'm assuming (x==-1) means truth and (y==-1) means truth, otherwise, false. You'll end up with this table:
Code:
```x=-1 | y=-1 | king true | result
(A) |  (B) |    (C)    |   (S)
_____|______|___________|_________________
0   |  0   |    0      |    1 = ~A~B~C
0   |  0   |    1      |    1 = ~A~BC
0   |  1   |    0      |    0
0   |  1   |    1      |    1 = ~ABC
1   |  0   |    0      |    1 = A~B~C
1   |  0   |    1      |    1 = A~BC
1   |  1   |    0      |    0
1   |  1   |    1      |    1 = ABC```
Using a kmap (as I showed before), you can simplify this with:

Which will result in S=~B || C. Your condition should be:
Code:
`if (y==1 || king ) ...`

5. trouble is i havent done demorgans and kaunaugh for about 25 years and then it confused me how you decided which square was A and which was ~A for example however i take your point all i need is the statment
if ((king == true || y == 1) && (x == -1 || x == 1)) as although x doesn't infulence the outcome i need to test that it is either 1 or -1

coop

6. Originally Posted by cooper1200
trouble is i havent done demorgans and kaunaugh for about 25 years and then it confused me how you decided which square was A and which was ~A
It is in the FIRST sentence on my text!
Originally Posted by cooper1200
for example however i take your point all i need is the statment
if ((king == true || y == 1) && (x == -1 || x == 1)) as although x doesn't infulence the outcome i need to test that it is either 1 or -1
Then, again, your truth table is wrong... There are 5 vars, not 6, unless "king" can be different from true or false.
With 5 vars you should have a truth table with 32 entries... with 6, 64...

Popular pages Recent additions