设为首页 加入收藏

TOP

C语言简单的菜单选项
2014-11-23 19:18:48 来源: 作者: 【 】 浏览:13
Tags:语言 简单 菜单 选项
#include 
  
   
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 \n");
			break;
			case 'b' : putchar('\a');
			break;
			case 'c' : count();
			break;
			default : printf("Buy adbcxz \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)
{
	char 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)
{
	char 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 .\n please enter an ");
		printf("integer value ,such as 25, -178, or 3:");
	}
	return input;
}


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Objective-C 浅析 下一篇C语言调用Lua函数

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: