8_8 menuette.c
Posted eisnull
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了8_8 menuette.c相关的知识,希望对你有一定的参考价值。
8_8 menuette.c -- 菜单程序
#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 = get_choice()) != 'q')
{
switch (choice)
{
case 'a':
printf("Buy low, sell high.\n");
break;
case 'b':
putchar('\a'); /* ANSI */
break;
case 'c':
count();
break;
default:
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, or 3: ");
}
return input;
}
以上是关于8_8 menuette.c的主要内容,如果未能解决你的问题,请参考以下文章
Xcode 8 Autocomplete Broken - 仅显示有限的用户代码片段 - 知道为啥吗?
内部格式为 GL_RGBA8 的纹理在片段着色器中显示为浮点数
错误记录Android Studio 编译报错 ( Could not determine java version from ‘11.0.8‘. | Android Studio 降级 )(代码片段