大佬们帮忙看下为啥会出现死循环
#include<stdio.h>#include<stdlib.h>
#include<math.h>
#include<time.h>
void menu()
{printf("*****欢迎进入小学生四则运算*****\n");
printf("1.加法\n");
printf("2.减法\n");
printf("3.乘法\n");
printf("4.除法\n");
printf("5.退出\n");
printf("按'Q'退出并重新选择运算方式");
}
void plu()
{int a,b,sum,c,flag=1;
char key;
do
{srand((unsigned)time(NULL));
a=rand(90)+10;
b=rand(90)+10;
sum=a+b;
printf("\n%d+%d=",a,b);
do
{scanf("%d",&c);
if(sum==c)
{printf("回答正确,请继续\n");break;}
else printf("回答错误,请重新回答\n");
}while(1);
printf("按任意键继续按'Q'返回重新选择运算方式");
if((key=getchar())=='Q')
flag=0;
}while(flag);
}
void sub()
{int a,b,sum,c,flag=1;
char key;
do
{srand((unsigned)time(NULL));
a=rand(90)+10;
b=rand(90)+10;
sum=a-b;
printf("\n%d-%d=",a,b);
do
{scanf("%d",&c);
if(sum==c)
{printf("回答正确,请继续\n");break;}
else printf("回答错误,请重新回答\n");
}while(1);
printf("按任意键继续按'Q'返回重新选择运算方式");
if((key=getchar())=='Q')
flag=0;
}while(flag);
}
void mul()
{int a,b,sum,c,flag=1;
char key;
do
{srand((unsigned)time(NULL));
a=rand(90)+10;
b=rand(90)+10;
sum=a*b;
printf("\n%d*%d=",a,b);
do
{scanf("%d",&c);
if(sum==c)
{printf("回答正确,请继续\n");break;}
else printf("回答错误,请重新回答\n");
}while(1);
printf("按任意键继续按'Q'返回重新选择运算方式");
if((key=getchar())=='Q')
flag=0;
}while(flag);
}
void divi()
{int a,b,sum,c,flag=1;
char key;
do
{srand((unsigned)time(NULL));
a=rand(90)+10;
b=rand(90)+10;
while(a%b!=0)
{a=rand(90)+10;
b=rand(90)+10;
}
sum=a/b;
printf("\n%d/%d=",a,b);
do
{scanf("%d",&c);
if(sum==c)
{printf("回答正确,请继续\n");break;}
else printf("回答错误,请重新回答\n");
}while(1);
printf("按任意键继续按'Q'返回重新选择运算方式");
if((key=getchar())=='Q')
flag=0;
}while(flag);
}
main()
{int key1;
do
{menu();
scanf("%d",&key1);
switch(key1)
{case 1:plu();
break;
case 2:sub();
break;
case 3:mul();
break;
case 4:divi();
}
}while(key1!=5);
}