石头剪刀布游戏 c++ 不显示 cout 来告诉谁赢得了比赛,我不知道出了什么问题,为什么程序不显示 cout。请告诉我出了什么问题、如何解决它以及为什么会发生,我认为 cstdlib 在那里什么也没做。
Objective: To score the rock-paper-scissors game. If the user enters invalid input, your program should say so, otherwise it will output one of the above results.
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
string pone;
string ptwo;
string r;
string p;
string s;
cout << "Rock, Paper, Scissors Game\n";
cout << "\nPlayer One, please enter your move: ('p' for Paper, 'r' for Rock, 's' for Scissor)";
cin >> pone;
cout << "\nPlayer Two, please enter your move: ('p' for Paper, 'r' for Rock, 's' for Scissor)";
cin >> ptwo;
if (pone == ptwo)
{
cout <<"\nThere is a tie"<<endl;
}
if ( pone == r && ptwo == p)
{
cout << "\nPaper wraps rock, Player 1 win";
}
else if (pone == r && ptwo == s)
{
cout << "\nRock smashes scissors, player 1 win";
}
if (pone == p && ptwo == r)
{
cout <<"\nPaper wraps rock, player 1 win";
}
else if ( pone == p && ptwo == s)
{
cout <<"\nScissors cut paper, player 2 win";
}
if ( pone == r && ptwo == p)
{
cout << "\nPaper wraps rock, Player 1 win";
}
else if (pone == r && ptwo == s)
{
cout << "\nRock smashes scissors, player 1 win";
}
if (pone == p && ptwo == r)
{
cout <<"\nPaper wraps rock, player 1 win";
}
else if ( pone == p && ptwo == s)
{
cout <<"\nScissors cut paper, player 2 win";
}
if ( ptwo == s && pone == r)
{
cout <<"\nScissors cut paper, player 1 win";
}
else if (ptwo == s && pone == p)
{
cout <<"\nRock smashes scissors, player 2 win ";
}
return 0;
}
最佳答案
这是你的问题:
if (pone == r && ptwo == p)
{
cout << "\nPaper wraps rock, Player 1 win";
}
else if (pone == r && ptwo == s)
{
cout << "\nRock smashes scissors, player 1 win";
}
//etc etc
将“r”、“p”和“s”放在引号中,如下所示:
if (pone == "r" && ptwo == "p")
//etc etc
你应该很好
关于c++ - 剪刀石头布游戏c++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22166766/