以下这个代码会跳过第二个if循环
#include "stdio.h"
int main()
{
int n;
char a='A';
while(1)
{
printf("please input a number\n");
scanf("%d",&n);
if(n%3==0||n%5==0)
printf("%d\n",n);
else printf("wrong\n");
printf("do you want to continue?plese input y or n\n");
scanf("%c",&a);
if(a=='n')
{
printf("end \n");
break;
}
else printf("continue\n");
}
return 0;
}
这是因为a读入的是整数后面的换行符,而不是字符
换成这样即可
#include "stdio.h"
int main()
{
int n;
char a='A';
while(1)
{
printf("please input a number\n");
scanf("%d",&n);
if(n%3==0||n%5==0)
printf("%d\n",n);
else printf("wrong\n");
printf("do you want to continue?plese input y or n\n");
scanf("\n%c",&a);
if(a=='n')
{
printf("end \n");
break;
}
else printf("continue\n");
}
return 0;
}
以下这个为怎样调试VC6.0的文章
http://www.cnblogs.com/zhangchenliang/p/3739115.html