#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 のいずれかでなければなりません。誰かが私がこれでどこを間違えたのか見ていますか?