这是我的代码:
#include <iostream>
using namespace std;
#include <ctime>
#include <cstdlib>
int main()
{
srand(time(0));
char computerChoice;
switch ( rand()%3)
{
case 0:
computerChoice = 'R';
case 1:
computerChoice = 'P';
case 2:
computerChoice = 'S';
}
cout << computerChoice;
}
每次运行程序时,我都会为 computerChoice 获得“S”,如果我循环该程序,我仍然会获得“S”。