64,691
社区成员
发帖
与我相关
我的任务
分享
int main(){
int a,char b;
srand((unsigned)time(0));
do{
double ran_num=rand()%10;
do{
cout<<"please enter a number between 1 to 10.\n";
cin>>a;
if (cin.bad())
{
cin.clear();
cin.sync();
continue;
}
else
{
if(a==0){
cout<<"data type error!\n";
b='y';
continue;
}
if(a<=0||a>=10){
cout<<"input a number between 1 to 10!\n";
b='y';
continue;
}
if(a!=ran_num&&a>ran_num){
cout<<"please input a lesser number\n";}
if(a!=ran_num&&a<ran_num){
cout<<"please input a lager number\n";}
}
}while(a!=ran_num);
cout<<"Gongratulation!\n";
do{
cout<<"\nContinue(yes or no)?\n";
b=getch();
}while(b!='y'&&b!='n');
}while(b=='y');
}