• C语言简单的菜单选项


    #include <stdio.h>
    char get_choice(void);
    char get_first(void);
    int get_int(void);
    void count(void);
    int main(){
    	int choice;
    	void count (void);
    	while ((choice =get_choice())!='q')
    	{
    		switch(choice)
    		{
    		   case 'a' : printf("Buy low ,shell high 
    ");
    			break;
    			case 'b' : putchar('a');
    			break;
    			case 'c' : count();
    			break;
    			default : printf("Buy adbcxz 
    ");
    			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)
    {
    	char 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)
    {
    	char 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;
    }
    
    

  • 相关阅读:
    最大流最小割——bzoj1001狼抓兔子,洛谷P2598
    求最小公因数和最大公倍数
    归并排序
    Splay
    Tarjan判断为什么不能把dfn写成low
    2-SAT问题
    离散数学-传递闭包(POJ3275)
    POJ3190
    安装环境gcc;
    二分折半排序
  • 原文地址:https://www.cnblogs.com/lcchuguo/p/5036989.html
Copyright © 2020-2023  润新知