我尝试了不同的方式来布置我的 if 语句,我什至尝试了嵌套的 if 语句。我得到相同的结果。除了显示我的代码之外,我不确定有什么方法可以问我的问题。
#include <iostream>
#include <conio.h>
#include <string>
using namespace std;
int main()
{
char playerOne, playerTwo;
cout<<"ROCK PAPER SCISSORS!"<<endl;
cout<<"Enter P for Paper"<<endl;
cout<<"Enter R for Rock"<<endl;
cout<<"Enter S for Scissors"<<endl;
cout<<"Player One enter your choice: ";
cin>>playerOne;
cout<<"Player Two enter your choice: ";
cin>>playerTwo;
if ((playerOne = 'R') && (playerTwo = 'R'))
cout<<"Both players played same hand";
else if ((playerOne = 'R') && (playerTwo = 'P'))
cout<<"Player Two wins!";
else if ((playerOne = 'R') && (playerTwo = 'S'))
cout<<"Player One wins!";
else if ((playerOne = 'P') && (playerTwo = 'R'))
cout<<"Player One wins!";
else if ((playerOne = 'P') && (playerTwo = 'P'))
cout<<"Both players played same hand";
else if ((playerOne = 'P') && (playerTwo = 'S'))
cout<<"Player Two wins!";
else if ((playerOne = 'S') && (playerTwo = 'R'))
cout<<"Player Two wins!";
else if ((playerOne = 'S') && (playerTwo = 'P'))
cout<<"Player One wins!";
else if ((playerOne = 'S') && (playerTwo = 'S'))
cout<<"Both players played same hand";
else
cout<<"Invalid inputs!";
getche();
return 0;
}