Search code examples
c++if-statementmultiple-conditions

Multiple, exclusive, conditions in an if statement


One of the first two statements in the if statement is false but I would like both of the first two statements to be false for the code to NOT run. please help.

void change(Shore* left, Shore* right, int ex, int can) {
        if (((ex!=left->lastMove[0]) && (can!=left->lastMove[1])) && (left->hasBoat)) {

I also tried the code below and that did not work either

        if ((ex!=left->lastMove[0] && can!=left->lastMove[1]) && left->hasBoat) {

Solution

  • void change(Shore* left, Shore* right, int ex, int can) {
        if (((ex!=left->lastMove[0]) || (can!=left->lastMove[1])) && (left->hasBoat)) {