各位大哥小弟刚学…问题有点低级不要见笑啊。
int main(void)
{
char sex,sports,diet ;
int a,b;
float hf,hm,hc ;
printf(“please input hf and hm\n”);
scanf (“%f%f”,&hf,&hm);
printf(“you are man or women?\n man input’M'women input’F'\n”) ;
{
char sex,sports,diet ;
int a,b;
float hf,hm,hc ;
printf(“please input hf and hm\n”);
scanf (“%f%f”,&hf,&hm);
printf(“you are man or women?\n man input’M'women input’F'\n”) ;
scanf(“%c”,&sex);
if (sex==’M') hc=(hf+hm)*0.54 ;
else hc=(hf*0.923+hm)/2;
printf (“Do you like physicd execise it?input ‘y’or’n'” );
scanf (“%c”,&sports);
if (sports==’y')hc*=1.02;
printf (“Do you have good eating habits?input ‘y’or’n'” ) ;
scanf(“%c”,&diet);
if (sex==’M') hc=(hf+hm)*0.54 ;
else hc=(hf*0.923+hm)/2;
printf (“Do you like physicd execise it?input ‘y’or’n'” );
scanf (“%c”,&sports);
if (sports==’y')hc*=1.02;
printf (“Do you have good eating habits?input ‘y’or’n'” ) ;
scanf(“%c”,&diet);
if (diet==’y')hc*=1.015;
printf(“hc=%f”,hc) ;
printf(“hc=%f”,hc) ;
getch();
return 0;
}
return 0;
}
这3个scanf 为什么有2个是没用的
程序运行时
想问下哪里错了?
#include <Stdio.h>
#include “Conio.h”
#include “Conio.h”
int main(void)
{
char sex,sports,diet ;
float hf,hm,hc ;
printf(“please input hf and hm\n”);
scanf (“%f%f”,&hf,&hm);
printf(“you are man or women?\n man input’M'womeninput’F'\n”) ;
sex=getch();
if (sex==’M') hc=(hf+hm)*0.54 ;
else hc=(hf*0.923+hm)/2;
printf (“Do you like physicd execise it?input ‘y’or’n'\n” );
sports=getch();
if (sports==’y')hc*=1.02;
printf (“Do you have good eating habits?input ‘y’or’n'\” ) ;
diet=getch() ;
if (diet==’y')hc*=1.015;
printf(“hc=%f”,hc) ;
{
char sex,sports,diet ;
float hf,hm,hc ;
printf(“please input hf and hm\n”);
scanf (“%f%f”,&hf,&hm);
printf(“you are man or women?\n man input’M'womeninput’F'\n”) ;
sex=getch();
if (sex==’M') hc=(hf+hm)*0.54 ;
else hc=(hf*0.923+hm)/2;
printf (“Do you like physicd execise it?input ‘y’or’n'\n” );
sports=getch();
if (sports==’y')hc*=1.02;
printf (“Do you have good eating habits?input ‘y’or’n'\” ) ;
diet=getch() ;
if (diet==’y')hc*=1.015;
printf(“hc=%f”,hc) ;
getch();
return 0;
}
return 0;
}
这个是改过的…
好像对的
>> 本文固定链接: http://www.vcgood.com/archives/2761
int main(void)
{
char sex,sports,diet ;
double hf,hm,hc ;
printf(“please input hf and hm\n”);
scanf (“%lf%lf”,&hf,&hm);
printf(“you are man or women?\n man input’M'women input’F'\n”) ;
scanf(“%c”,&sex);
if (sex==’M') hc=(hf+hm)*0.54 ;
else hc=(hf*0.923+hm)/2;
printf (“Do you like physical exercise it?input ‘y’or’n'” );
scanf (“%c”,&sports);
if (sports==’y')hc*=1.02;
printf (“Do you have good eating habits?input ‘y’or’n'” ) ;
scanf(“%c”,&diet);
if (diet==’y')hc*=1.015;
printf(“hc=%lf”,hc) ;
return 0;
}
scanf没有问题,而是程序有小错误!
float最好改成double
把最后的getch()去掉
楼主
我用的是win-tc
用个getch()是为了使他输出结果保留下
float和double 都没用;
只是
输出结果是:蓝的为键盘输入
please input hf and hm
170
170
you are man or women?
man input’M'women input’F' 就是这个问题!本来这里会要求用户输入一个字符的,可是直接跳过了
Do you like physicd execise it?input ‘y’or’n’
我不知道怎么上传图片呵呵…要不然更明白了
scanf()是用来读取字符串的,所以不能写成scanf(“%c”,&**),可以将c改成s,或改用getchar().
楼上说的也对!
不过scanf(“%c”,&**),错了是缓存区的问题
加一个fflush(stdin);就能解决了
第一次你用SCANF来进行输用,格式如下
170 _
170_
进行了两次换行,当第二次进行输入%C的时候,系统自动读’\N’,'\r’,
你可以把下面的输入变成%d格式,或者多写一次SCANF
你也可以用以下语句,来进行输入,
SCANF(“%2C”,&SEX);
我在前面加了个2,屏蔽掉了换行符
在scanf输入上面用这个好
fflush(stdin);
清空缓存