zoukankan      html  css  js  c++  java
  • 菜单技术

    <span style="font-size:18px;">#include <stdio.h>
    #include <stdlib.h>
    
    char get_choice(void);
    char get_first(void);
    
    int get_int(void);
    void count(void);
    
    int main(void)
    {
        int choice;
        while((choice = get_choice())!='q')
        {
            switch(choice)
            {
                case 'a':
                printf("Buy low,sell high.
    ");
                break;
                case 'b':
                putchar('a');
                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 integer:
    ");
        n = get_int();
        for( i = 0; 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,d,and 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);<span style="white-space:pre">				</span>/* 剔除错误的输入 */
            printf(" is not an integer.
     Please enter an integer value,such as 25,-178,or 3:");
        }
        return input;
    }
    </span>

  • 相关阅读:
    技术博客之Saju M
    Dajax 的安装以及详细使用
    当我感觉厌倦的时候
    2014年3月22日 星期日
    windows 7远程桌面访问 ubuntu12.04
    promise的用法
    for循环中匿名同步
    开启Group Work Site功能
    Jquery根据属性模糊查询节点
    设置用户字段
  • 原文地址:https://www.cnblogs.com/slgkaifa/p/6863249.html
Copyright © 2011-2022 走看看