mardi 25 juillet 2017

Using multiple conditions in an if statement in C++

I am trying to create a complex if statement in C++ that will save me from writing a whole bunch of if statements, I am wondering if this code below actually makes sense or I am overlooking an error.

if(input==choice) {
        cout << "Tie!" << endl;
}else if(input=="rock" && choice=="scissors"
     || input=="scissors" && choice=="paper"
     || input="paper" && choice=="rock") {
        cout << input " beats " << choice << ", you win!" << endl;
}else if(input=="rock" && choice=="paper"
    || input=="scissors" && choice=="rock"
    || input=="paper" && choice=="scissors"){
        cout << choice << " beats " << input << ", you lose!" << endl;
}

What I am trying to achieve is:

"if input is x AND choice is y, OR if...."

Basically I'm testing multiple "if-and" conditions so that a single line of code will execute if it hits any of the if-and conditions. The output throws a "no match for 'operator||'" error.

Aucun commentaire:

Enregistrer un commentaire