#include <ctime>
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
// initialize the computer's random number generator
srand(time(0)); rand();
// declare variables
char c1;
char c2;
char c3;
c1 = 'R';
c2 = 'P';
c3 = 'S';
// start loop
while (true)
{
// determine computer's choice
int result = rand() % 3; // 0 or 1 or 2
if (result == 0)
result = c1;
if (result == 1)
result = c2;
if (result == 2)
result = c3;
// prompt for, and read, the human's choice
char humanChoice;
cout << "Rock, Paper, or Scissors? [R/P/S or Q] ";
cin >> humanChoice;
cin.ignore(1000, 10);
// if human wants to quit, break out of loop
if (humanChoice == 'Q') break;
// print results
cout << result << endl;
cout << humanChoice << endl;
// end loop
}
// end program
return 0;
}
伙计们怎么了?我正在进行我的中期项目的第一步,即创建一个石头剪刀布游戏。这只是开始,我还远未完成,但我已经遇到了错误。当我编译并运行它时,我得到计算选择了数字 83,它必须是 rp 或 s。有谁看到我哪里出错了?