回复计划游戏结果不会显示
RSP Game results won't show up
我正在为我的下一个盘子做一个剪刀石头布游戏,我想缺少一些东西,我只是想不通。这是我到目前为止所做的,我所需要的只是得到谁赢的结果,比如"PLayer 1 Wins"或"这是一个平局"。会不会是循环?字符初始化似乎也是错误的。 请启发我,我很感激任何答案!这是输出显示的内容。
编辑:
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <stdlib.h>
#include <Windows.h>
using namespace std;
class Game
{
private: int rndNum, result;
char P1, P2, repeat;
const char R = 'R', S = 'S', P = 'P';
public: void RSPLogic();
};
void Game::RSPLogic()
{
do {
cout << "Input choice of player 1 : ";
cin >> P1;
cout << "Input choice of player 2 : ";
srand(time(0));
rndNum = rand() % 3;
if (rndNum == 0) //Computer rock
{
P2 = 0;
cout << "Rn";
}
else if (rndNum == 1) //Computer scissors
{
P2 = 1;
cout << "Pn";
}
else if (rndNum == 2) // Computer paper
{
P2 = 2;
cout << "Sn";
}
//Player 1 Win
if ((P1 == 'R' && P2 == 1) || (P1 == 'S' && P2 == 2) || (P1 = 'P' && P2 == 0))
cout << endl << "Player 1 Wins!" << endl << endl;
//Player 2 Win
else if ((P1 == 'R' && P2 == 2) || (P1 == 'S' && P2 == 0) || (P1 == 'P' && P2 == 1))
cout << endl << "Player 2 Wins!" << endl << endl;
//Tie
else if ((P1 == 'R' && P2 == 0) || (P1 == 'S' && P2 == 1) || (P1 == 'P' && P2 == 2))
cout << endl << " It's a Tie!" << endl << endl;
cout << endl << "Press [Y/y] to continue." << endl;
cin >> repeat;
repeat = toupper(repeat);
}
while (repeat == 'Y');
}
int main()
{
Game obj;
obj.RSPLogic();
system("pause");
return 0;
}
将方法的开头更改为此肯定会有所帮助
cout << "Input choice of player 1 : ";
cin >> P1;
cout << "Input choice of player 2 : ";
cin >> P2;
您错过了播放器 2 输入
同样出于某种原因,您将P1
与字符进行比较,但P2
与整数进行比较。
else if ((P1 == 'R' && P2 == 0) ...
应该是
else if ((P1 == 'R' && P2 == 'R') ...
等等等等
相关文章:
- 代码未在联机编译器上显示结果
- 我的循环超时并且不显示结果
- C 可执行文件从浏览器下载而不是显示结果
- 如果满足嵌套条件,则计算结果未显示结果C
- 使用 std::async 准备好后立即显示结果
- if, else if, else 函数未准确显示结果
- C++:如何在控制台窗口中显示结果
- VIM:执行复杂文件类型的脚本和显示结果
- 根据标准对结构向量进行排序,然后显示结果
- c++将var从一个函数传递到另一个函数,然后在主函数中显示结果
- 当结果超过 100 时,程序不显示结果
- 对输入'age'名称进行排序,然后显示结果
- 代码可以运行,但不在 Eclipse 中显示结果。
- 将代码C++到 MIPS 中,MIPS 中的代码运行时没有错误消息,但不显示结果
- 为什么使用 scanf() 时显示结果有延迟
- 如何使用信号和插槽从qt表单中获取id,然后在链表中搜索它并使用另一个表单显示结果
- C++不显示结果
- 最长公共子序列没有显示结果
- C++需要在Main()调试中显示结果的帮助
- C/C++读取UART端口并显示结果