| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 911 人关注过本帖
标题:编的程序有点问题 求大神指点
只看楼主 加入收藏
亲琪琪
Rank: 2
等 级:论坛游民
帖 子:55
专家分:38
注 册:2016-3-12
结帖率:70%
收藏
已结贴  问题点数:20 回复次数:2 
编的程序有点问题 求大神指点
# include<stdio.h>
int main()
{
char name[10];
char sex;
double maths,english,computer;
int age;
printf("please enter your name age sex:");
scanf("%s%d %c",&name,&age,&sex);
printf("piease enter your scores(maths,english,computer):");
scanf("%f%f%f",&maths,&english,&computer);
(maths>=90&&english>=90&&computer>=90)?printf("You are excellent\n"):printf("You should study hard\n");
return 0;
}
为什我每次无论输入那三个数  结果都是You should study hard
搜索更多相关主题的帖子: computer english please double return 
2016-03-22 15:47
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9009
专家分:53957
注 册:2011-1-18
收藏
得分:15 
%f 改为 %lf
2016-03-22 16:02
hjx1120
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:李掌柜
等 级:贵宾
威 望:41
帖 子:1314
专家分:6927
注 册:2008-1-3
收藏
得分:5 
# include<stdio.h>
int main()
{
    char name[10];
    char sex;
    double maths,english,computer;
    int age;
    printf("please enter your name age sex:");
    scanf("%s%d%c",&name,&age,&sex);
    while (getchar() != '\n')
        continue;
    printf("piease enter your scores(maths,english,computer):");
    scanf("%lf%lf%lf",&maths,&english,&computer);
    while (getchar() != '\n')
        continue;
    (maths>=90&&english>=90&&computer>=90)?printf("You are excellent\n"):printf("You should study hard\n");
   
    return 0;
}
缓冲区没有清除,
回车符(\n)的ASCII码小于90,
所以楼主不管输入多大的数字
结果都是“你应该努力学习”
2016-03-22 16:28
快速回复:编的程序有点问题 求大神指点
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020285 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved