部分代码如下,在Choose函数中:想使用一个循环,结果在第一个那个部分进行选择时出现错误,
选择Choicepass()函数后,Choicepass()函数仅仅执行到"scanf("%c",&M);",
再直接进入Choose函数中的" printf("是否重新进行?\nc->继续\ne->退出:");"这条语句。
想要知道为什么,求大神为新手求解,万分感谢!
结果如图:
图片说明!
int Choicepass()
{
int n,T,L,S1,S2,S3;
char M;
printf("Please choose the model:\na->easy\nb->normal\nc->difficulty\n:");
scanf("%c",&M);
switch(M) //选择难度所用函数
{
case 'a':
{
srand(time(0));
n = rand()%10+1;
T = 3;
S1 = Guess1(n,T);
}break;
case 'b':
{
srand(time(0));
n = rand()%50+1;
printf("You should get the answer from 1~50.\nPlease choose the TimesLimit(5~10):");
scanf("%d",&T);
S2 = Guess2(n,T);
}break;
case 'c':
{
srand(time(0));
n = rand()%100+1;
printf("You should get the answer from 1~100.\nPlease choose the TimesLimit(5~15):");
scanf("%d",&T);
S3 = Guess3(n,T);
}break;
}
L = 1;
return L ;
}
/*选择关卡模式或者选择难度模式*/
int Choose()
{
int L,T;
char k,h;
printf("选择关卡模式或者自由选择难度模式:\ng->关卡\nz->自由:");
scanf("%c",&h);
if(h == 'c')
L = Customspass();
else if(h == 'z')
L = Choicepass();
else printf("ERROR!\n");
printf("是否重新进行?\nc->继续\ne->退出:");
scanf("%c",&k);
if(k == 'c')
T = Choose();
else
printf("游戏结束!\n");
return T;
}