|
|
发表于 2013-8-27 19:44:58
|
显示全部楼层
貌似好了 没怎么仔细看- #include<stdio.h>
- char get_choice();//输入
- char get_first();//
- int get_int();//输入类型确认,为整数型
- void count();//count计算
- int main()
- {
- int choice;
- void count();
- while((choice=get_choice())!='q')
- {
- switch(choice)//标签
- {
- case 'a':printf("Buy low,sell high.\n");
- break;
-
- case 'b':putchar('\a');
- break;
-
- case 'c':count();
- break;
-
- default:printf("program error\n");
- break;
- }
-
- }
- printf("Bye!");
- return 0;
- }
- void count()
- {
- int n,i;
- printf("Count how far?Enter an ingeter.\n");
- n=get_int();
- for(i=1;i<=n;i++)
- printf("%d\n",i);
- while(getchar()!='\n')
- continue;//δ践?
- }
- char get_choice()
- {
- int ch;
- printf("Enter the letter of your choice.\n");
- printf("a:advice b:bell\n");
- printf("c:count q:quit\n");
- ch=get_first();
- while((ch<'a'||ch>'c')&&ch!='q'){
- printf("Please enter a,b,c or q.\n");
- ch=get_first();
-
- }
- return ch;
- }
- char get_first()
- {
- int ch;
- while((ch=getchar())==' ')//屏蔽空格
- ;
- ungetc(ch,stdin);//将第一个送回
- ch = getchar();
- return ch;
- }
- int get_int()
- {
- int input;
- char ch;
- while(scanf("%d",&input)!=1)
- {
- while((ch=getchar())!='\n')
- putchar(ch);
- printf(" is not an ingeter.\nPlease enter an ingeter value\
- such as 25,-178 or 3.\n ");
- }
- return input;
- }
复制代码 |
|