各位看官过来帮帮菜鸟。
要求出入1-4,其它的输入都是错误,重新输入。c代码如下,可是当输入错误时,总是显示2次"Invalid value entered. Must be 1 to 4, please re-enter:"。请大虾指教。我是在dev c++上运行。#include<stdio.h>
#include<stdlib.h>
main()
{ int a=1; char k;
printf("Enter Section Number:");
while(a)
{
k=getchar();
if (k<'5'&&k>'0') a=0;
else printf("Invalid value entered. Must be 1 to 4, please re-enter:");
}
printf("%c",k);
system("pause");
return 0;
}