【发布时间】:2014-02-18 04:08:03
【问题描述】:
#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 下重现它,即使在 ideone.com/C88qG3 中也是如此?
-
@herohuyongtao g++ 和我在终端做它
标签: c++ character infinite-loop do-while