#include<iostream>
#include<cstdlib>
#include<ctime>
#include<string>
using namespace std;
int main()
{
char replay;
int userInput;
cout<< "Let's play Rock, Paper, Scissors"<<endl;
do
{
cout<<"Enter 1 for Rock, 2 for Paper, 3 for Scissors"<< endl;
cin>> userInput;
switch(userInput)
{
case 1:
cout <<"You chose rock" << endl;
break;
case 2:
cout <<"You chose paper" <<endl;
break;
case 3:
cout <<"You chose scissors" << endl;
break;
default:
cout << userInput << " is not a valid choice"<< endl;
break;
}
cout<<"Would you like to play again (Y for yes, N for no)?"<<endl;
cin >> replay;
} while((replay=='Y') || (replay=='y'));
return 0;
}
当我在输入数字的回答中输入一个字符时,当我被问及是否要再次玩时,输入的字符不是Y,Y,N或n时,进入无限循环为什么我的程序在输入字符时会出现无限循环?
你在使用,因为我不能复制VS2010下,即使是在HTTP编译:// ideone .COM/C88qG3? – herohuyongtao
@herohuyongtao g ++和我在终端 – user2988803