我已經嘗試過佈置if語句的不同方式,我甚至嘗試過嵌套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;
}
您可能會先告訴他們有什麼問題,以便我們幫助您瞭解如何解決問題。 – Tim
編譯器應該用這段代碼產生了一些警告,你是否注意到了它們? –