I've written a basic program to play Rock Paper Scissors with a user. If the user beats the cpu, "You beat the computer!" is supposed to be displayed. If the cpu beats the user, "Rats! The computer won." is supposed to be displayed.
This works brilliantly, except for when either the user or the cpu chooses scissors. Then, their respective choices are displayed like they are supposed to be, but neither of the above messages is displayed.
The problem is only involving scissors. Everything I wrote involving scissors is exactly the same as for paper and rock, as far as I can tell... am I missing a glaring issue?
Please help!
Code:#include <iostream> #include <cstdlib> #include <ctime> using namespace std; int main() { //Define srand(time(0)); int cpuMove = rand() % 3; //Prompt user cout << "Enter 0(rock), 1(paper) or 2(scissors) > "; int userMove; cin >> userMove; //State user's move if (userMove == 1) cout << "You played paper." << endl; else if (userMove == 2) cout << "You played scissors." << endl; else if ((userMove > 2) || (userMove <= 0)) userMove = 0; if (userMove == 0) cout << "You played rock." << endl; //State computer's move if (cpuMove == 1) cout << "The computer played paper." << endl; else if (cpuMove == 2) cout << "The computer played scissors." << endl; else cout << "The computer played rock." << endl; //Declare winner if ( (userMove == cpuMove) || ((userMove == 1) && (cpuMove == 0)) || ((userMove = 0) && (cpuMove == 2)) || ((userMove == 2) && (cpuMove = 1)) ) cout << "You beat the computer!" << endl; if ( ((userMove == 1) && (cpuMove == 2)) || ((userMove == 0) && (cpuMove == 1)) || ((userMove == 2) && (cpuMove == 0)) ) cout << "Rats! The computer won." << endl; system("pause"); return 0; }