C++ 剪刀石头布游戏 如何限定玩3次 然后询问是否继续

cout << "1 means rock; 2 means scissors; 3 means paper;0 means quit." <<endl;
cout << "Please Enter" <<endl;
int n;
while(cin >> n)
{
if(n < 0 || n > 3)
cout << "Error, Please enter again!!!" << endl;
else if(n == 0)
break;
else
{
int compplay;
srand((unsigned)time(0));
compplay = rand()%3 + 1;
switch(n)
{
case 1: cout << "You pick rock" << endl; break;
case 2: cout << "You pick scissors" << endl; break;
case 3: cout << "You pick paper" << endl; break;
}
switch(compplay)
{
case 1: cout << "Computer picks rock" << endl; break;
case 2: cout << "Computer picks scissors" << endl; break;
case 3: cout << "Computer picks paper" << endl; break;
}
if(compplay == n) cout<<"Tied"<<endl;
else if(compplay - n == 1) cout <<"You win" << endl;
else if(compplay == 1 && n == 3) cout <<"You win" << endl;
else cout << "You lose" << endl;
}
}
如何让 限定三次 之后需要询问是否继续 是的话 就输入 Y 否的话 输入N

在循环里加一个读数变量 k 就可以了;
每一次都k++;
if(k>3)
cout<<"是否继续?";
int f;
cin>>f;
if(f=1)//不继续
return;
else
k=0;
温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-05-04
在外面再套一while