c primer plus 程序清单8.8 分析不出 请教
程序清单8.8 菜单技术#include <stdio.h>
char get_choice (void):
char get_first (void):
int get_int (void):
void count(void):
int main (void)
{
int choice;
void count (void);
while ((choice = getchoice ()) != 'g')
{
switch
{
case 'a':printf("Buy low.sell high\n");
break;
case 'b':ptuchar('\a'):
break;
case 'c':count();
break;
defalut:printf("program error!\n");
break;
}
}
printf("Bye .\n");
return 0;
}
void count (void)
{
int n,i;
printf("count how far?Enter an integer:\n");
n = get_int();
for (i = 1;i <= n; i++)
printf("%d\n",i);
while (getchar() != '\n')
continue;
}
char get_choice(void)
{
int ch;
printf("Enter the letter of your choice: \n");
printf("a.advice b.bell\n");
printf("c.count d.quit\n");
ch = get_first();
while ((ch < 'a' || ch > 'c')&& ch != 'q' )
{
printf("please respond with a,b,c,or q.\n");
ch = get_first;
}
return ch;
}
char get_first(void)
{
int ch;
ch = getchar();
while (getchar() != ‘\n’)
continue;
return ch;
}
int get_int (void)
{
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,pr 3: ");
}
return input:
}