某书上的一道题,从键盘输入一个正整数,如过是7的倍数就输出到屏幕。要求不断输入与输出,
直到使用者选择退出。
#include <stdio.h>
#include <conio.h>
main()
{
   int t=0;
   char flag='\0';
   do
   {   printf("\nPlease input the num :");
       scanf("%d",&t);
       if (t%7==0)
          printf("\nCannot be output!");
       else
          printf("\nthe number canbe output:%d",t);
          printf("\nContinue?(Y/N)");
       do{
          scanf("%c",&flag);
       }while(flag!='y'&&flag!='Y'&&flag!='n'&&flag!='N');
   }while(flag=='y'||flag=='Y');
   printf("Press any key to quit the window...");
   getch();
}
现在这样写运行是正常的(win-tc)。
但把红色部分改为
 
       do{printf("\nContinue?(Y/N)");
          scanf("%c",&flag);
       }while(flag!='y'&&flag!='Y'&&flag!='n'&&flag!='N');
这样就出现问题了:跳出两行  Continue?(Y/N)  ,也就是printf("\nContinue?(Y/N)");运行了两次,为何????
红色部分再改一下,只写
          printf("\nContinue?(Y/N)");
          scanf("%c",&flag);
也就是不要检查字符是否为y、n的循环,运行到 Continue?(Y/N) 时就输入不了字符了,为什么???

 
											





 
	    


