if statement conditions

I have what I feel like should be an easy logical error to solve but I do not know how to properly write the "if statement".

Given the 4 options of W, X, Y, and Z in a section box of 6 slots where every letter is an option for each box.

I have a counter that goes through and counts the number of times each letter in this box appears.

This is where the problem arises: The only conditions that I want to pass as true are "all 6 slots occupied with X" OR "5 slots occupied with X AND 1 slot occupied with Y"

Something like this: x_ x_ x_ x_ x_ x_ OR y_ x_ x_ x_ x_ x_ (or any of the the other five combinations of this)

All other combinations of the slots filled to pass as false! To then trigger an error message

could someone help me with what i'm doing wrong?

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
29
30
31
32
33
34
35
36
37
38
someBool = true;

int x= 0;
int y= 0;

 if ( var->slot_1() == X )
        {
            ++x;

        }
        else if ( var->slot_1() == Y )
        {
            ++y;
        }
 if ( var->slot_2() == X )
        {
            ++x;

        }
        else if ( var->slot_2() == Y )
        {
            ++y;
        }

// And so on for the 6 slots.

  if( ( ! x == 6 ) || ( ! ( x == 5 && y == 1))
{
    someBOOL = false;
} 



if ( ! someBOOL )
{
 return (invalidMessageFunctionMessage( tr(YOU WRONG));
}


THANK YOU
Watch your operator precedence.

 
someBOOL = (x == 6) or ((x == 5) and (y == 1));

Notice how closely this aligns with your written statement.

Hope this helps.
Thank you
I was thinking and saying it properly, but not writing it properly.

what I wanted was

1
2
3

if(! ( ( x==6 )|| ( x ==5  && y == 1 ) ) )


https://en.cppreference.com/w/cpp/language/operator_precedence
Nice!
Topic archived. No new replies allowed.