首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

关于c语言的一个小编程有关问题 求大神解释上

2013-03-22 
关于c语言的一个小编程问题 求大神解释下#includestdio.hchar get_choice(void)char get_first(void)i

关于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':printf('\a');
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 lerrer of your choice:\n");
printf("a. advice              b. bell\n");
printf("c. count               q.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;
}


第一 运行后第一句不应该是先显示Count how far?Enter an integer:这句话么?为什么是菜单
第二 我选择b的话 应该响蜂鸣的声音才对 为什么用老是出现错误 运行不了呢 c 编程
[解决办法]
while((choice=get_choice())!='q')
{
switch(choice)
{
case 'a':printf("Buy low sell high.\n");
break;
case 'b':printf('\a');  //改为case 'b':printf("\a");
break;
case 'c':count();
break;
default:printf("Program error!\n");
break;

}
}
[解决办法]


#include<stdio.h>
void count(void);
char get_choice(void);
char get_first(void);
int get_int(void);
int main(void)
{
int choice;
count();//这里你写成了 void conut(void);
while((choice=get_choice())!='q')
{
switch(choice)
{
case 'a':
printf("Buy low sell high.\n");
break;
case 'b':
printf("\a");//这里你写成了printf('\a');
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 lerrer of your choice:\n");
printf("a. advice              b. bell\n");
printf("c. count               q. 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;
}

热点排行