貌似只有在运行减号的时候出问题
我设置了a 1.运行卡住了
2.a比b小
3.是正常的a大于b
#include
#include
#include
main()
{
int a,b,c,sign,max,i=1;
char sign1;
printf("Please input a number ('1'or others, 1:-;others:+)输入1为减号,输入其他数字为正号只能输入数字\n");
scanf("%d",&sign);
printf("Please input the MAX number\n");
scanf("%d",&max);
srand(time(NULL));
a=rand()%max;
b=rand()%max;
while(a<b&&sign==1);
{
a=rand()%max;
b=rand()%max;
printf("1;\n");
}
sign1=(sign==1?'-':'+');
while(i)
{
printf("%d%c%d=",a,sign1,b);
scanf("%d",&c);
if(sign==1&&a-b==c)
{
printf("YES!");
i=0;
}
else if(sign!=1&&c==(a+b))
{
printf("YES!");
i=0;
}
else
{
printf("NO!");
i=1;
}
}
}
这行错了,循环后多了个分号。
这样的程序用调试器一调试几分钟就找到问题了。
具体的IDE有,vs2005 vs2008 vs2010 vs2012 vs2013 vs2015 vs2017 , codeblocks , Netbeans ,
在linux 使用 gdb 调试器或者使用codeblocks.
while(a<b&&sign==1);