zoukankan      html  css  js  c++  java
  • 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.
    ");
                    break;
                case 'b':
                    putchar('a');                 /* ANSI  */
                    break;
                case 'c':
                    count();
                    break;
                default:
                    printf("Program error!
    ");
                    break;
            }
        }
        printf("Bye.
    ");
    
        return 0;
    }
    
    void count(void)
    {
        int n, i;
    
        printf("Count how far? Enter an integer:
    ");
        n = get_int();
        for (i = 1; i <= n; i++)
            printf("%d
    ", i);
        while (getchar() != '
    ')
            continue;
    }
    
    char get_choice(void)
    {
        int ch;
        printf("Enter the letter of your choice:
    ");
        printf("a. advice         b. bell
    ");
        printf("c. count          d. quit
    ");
        ch = get_first();
        while ((ch < 'a' || ch > 'c') && ch != 'q')
        {
            printf("Please respond with a, b, c, or q.
    ");
            ch = get_first();
        }
    
        return ch;
    }
    
    char get_first(void)
    {
        int ch;
        ch = getchar();
        while (getchar() != '
    ')
            continue;
    
        return ch;
    }
    
    int get_int(void)
    {
        int input;
        char ch;
    
        while (scanf("%d", &input) != 1)
        {
            while ((ch = getchar()) != '
    ')
                putchar(ch);   // 处理错误输出
            printf(" is not an integer.
    Please enter an ");
            printf("integer value, such as 25, -178, or 3: ");
        }
    
        return input;
    }
  • 相关阅读:
    牢骚
    【题解】LFYZNoip前水题赛 T6
    【模板】 ST表
    【模板】高精度。。。。。
    【模板】堆优化 + dij +pair 存储
    【模板】树状数组
    近两天目标
    当堆遇到STL 代码焕发光芒
    【模板】并查集
    【NOI2000】 单词查找树
  • 原文地址:https://www.cnblogs.com/EisNULL/p/10854427.html
Copyright © 2011-2022 走看看