一个关于菜单的题目
#include<stdio.h>char input();
char ppp();//去除换行符的影响
void count();
int kk();
int main()
{
int shu;
while((shu=input())!='q')
{
switch(shu)
{
case 'a': printf("buy low,sell high.\n");
break;
case 'b': putchar('\a');
break;
case 'c': count();
break;
default: printf("error\n");
break;
}
}
return 0;
}
char input()
{
int ch;
printf("enter numerejh fjk\n");
printf("a.advice b.'shengy'\n");
printf("c.count d.oijj\n");
ch=ppp();
while((ch<'a'||ch>'c')&&ch!='q')
{
printf("a,b,or q\n ");
ch=ppp();
}
return ch;
}
char ppp()
{
char hh;
hh=getchar();
while(getchar()!='\n')
continue;
return hh;
}
void count()
{
int i,n;
printf("enter number:");
n= kk();
for(i=1;i<=n;i++)
printf("%d\n",i);
while(getchar!='\n')
continue;
}
int kk()
{
int input;
char ch;
while(scanf("%d",&input)!=1)
{
while((ch=getchar())!='\n')
putchar(ch);
printf("is not an integer.\nplease enter an");
printf("integer value.such as 25,-178,or 3:");
}
return input;
}
当你输入c后enter再随便输入一个数字enter,再然后就不能输入了,我设计的是可以输入的请各位大亨帮我 找找原因