标题:作业,帮看看哪错了。。。
只看楼主
ai_44
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2011-9-26
结帖率:66.67%
已结贴  问题点数:5 回复次数:8 
作业,帮看看哪错了。。。
程序代码:
#include <stdio.h>
int main1()
{
    double sex,high,weight,goodweight;
    printf("请输入您的性别,男=1,女=0,sex= \n");
    scanf("%d\n",&sex);
    printf("请输入您的身高(单位cm),high= \n");
    scanf("%f\n",&high);
    printf("请输入您的体重(单位KG),weight= \n");
    scanf("%f\n",&weight);

    if(sex)      { goodweight = (high-100)*0.9;}
     else         {goodweight = (high-100)*0.9-2.5;}    
    if((weight <= 0.6*goodweight))       
        printf("很遗憾,您已经脱离正常人范围了,请立即去救助站~!");   
    if((weight >= 0.6*goodweight))&&((weight <= 0.8*goodweight))      
        printf("您处于消瘦状态,请增重%dkg,多吃多锻炼",(int)(goodweight-weight+1));  
    if((weight >= 0.8*goodweight))&&((weight <= 0.9*goodweight))      
        printf("您处于偏瘦状态,请增重%dkg,适当锻炼身体",(int)(goodweight-weight+1));  
    if((weight >= 0.9*goodweight))&&((weight <= 1.1*goodweight))      
        printf("恭喜您,您的体重正常,请保持",);  
    if((weight >= 1.3*goodweight))&&((weight <= 1.5*goodweight))     
        printf("您处于偏胖状态,请减轻%dkg,多吃蔬菜少吃肉",(int)(weight-goodweight+1));   
    if((weight >= 1.5*goodweight))&&((weight <= 1.8*goodweight))    
        printf("您处于肥胖状态,请减轻%dkg,只吃蔬菜不吃肉",(int)(weight-goodweight+1));   
    if((weight >= 0.6*goodweight))     
        printf("我对您深表同情。。。");             
   
        getchar();       
        getchar();   
        return 0;
} 




错误    4    error C2143: 语法错误 : 缺少“;”(在“&&”的前面)  

警告    5    warning C4390: “;”: 找到空的受控语句;这是否是有意的?   
搜索更多相关主题的帖子: high 
2011-10-16 22:35
embed_xuel
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:58
帖 子:3845
专家分:11385
注 册:2011-9-13
得分:1 
错误太多,给你改完了,自己对比一下,没验证运行情况。
#include <stdio.h>
int main()
{
    double sex,high,weight,goodweight;
    printf("请输入您的性别,男=1,女=0,sex= \n");
    scanf("%d\n",&sex);
    printf("请输入您的身高(单位cm),high= \n");
    scanf("%f\n",&high);
    printf("请输入您的体重(单位KG),weight= \n");
    scanf("%f\n",&weight);

    if(sex)      { goodweight = (high-100)*0.9;}
     else         {goodweight = (high-100)*0.9-2.5;}   
    if(weight <= 0.6*goodweight)      
        printf("很遗憾,您已经脱离正常人范围了,请立即去救助站~!");   
    if((weight >= 0.6*goodweight)&&(weight <= 0.8*goodweight))      
        printf("您处于消瘦状态,请增重%dkg,多吃多锻炼",(int)(goodweight-weight+1));  
    if((weight >= 0.8*goodweight)&&(weight <= 0.9*goodweight))      
        printf("您处于偏瘦状态,请增重%dkg,适当锻炼身体",(int)(goodweight-weight+1));  
    if((weight >= 0.9*goodweight)&&(weight <= 1.1*goodweight))      
        printf("恭喜您,您的体重正常,请保持");  
    if((weight >= 1.3*goodweight)&&(weight <= 1.5*goodweight))     
        printf("您处于偏胖状态,请减轻%dkg,多吃蔬菜少吃肉",(int)(weight-goodweight+1));   
    if((weight >= 1.5*goodweight)&&(weight <= 1.8*goodweight))   
        printf("您处于肥胖状态,请减轻%dkg,只吃蔬菜不吃肉",(int)(weight-goodweight+1));   
    if(weight >= 0.6*goodweight)     
        printf("我对您深表同情。。。");            
   
        getchar();      
        getchar();   
        return 0;
}

总有那身价贱的人给作业贴回复完整的代码
2011-10-16 22:40
laoyang103
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:内蒙古包头
等 级:贵宾
威 望:19
帖 子:3082
专家分:11056
注 册:2010-5-22
得分:1 
把从第二个开始的if都改成else if 来加速你的程序

                                         
===========深入<----------------->浅出============
2011-10-16 22:44
ai_44
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2011-9-26
得分:0 
程序代码:
#include <stdio.h>
int main()
{
    double sex,high,weight,goodweight;
    printf("请输入您的性别,男=1,女=0,sex= \n");
    scanf("%d\n",&sex);
    printf("请输入您的身高(单位cm),high= \n");
    scanf("%f\n",&high);
    printf("请输入您的体重(单位KG),weight= \n");
    scanf("%f\n",&weight);

    if(sex)
        {goodweight = (high-100)*0.9;}
   
    else
        {goodweight = (high-100)*0.9-2.5;}
    if(weight <= 0.6*goodweight)
        printf("很遗憾,请珍惜最后的时光~");
    else if((weight >= 0.6*goodweight)&&(weight <= 0.8*goodweight))
        printf("您处于消瘦状态,请增重%dkg,多吃多锻炼",(int)(goodweight-weight+1));
    else if((weight >= 0.8*goodweight)&&(weight <= 0.9*goodweight))
        printf("您处于偏瘦状态,请增重%dkg,适当锻炼身体",(int)(goodweight-weight+1));
    else if((weight >= 0.9*goodweight)&&(weight <= 1.1*goodweight))
        printf("恭喜您,您的体重正常,请保持",);
    else if((weight >= 1.3*goodweight)&&(weight <= 1.5*goodweight))
        printf("您处于偏胖状态,请减轻%dkg,多吃蔬菜少吃肉",(int)(weight-goodweight+1));
    else if((weight >= 1.5*goodweight)&&(weight <= 1.8*goodweight))
        printf("您处于肥胖状态,请减轻%dkg,只吃蔬菜不吃肉",(int)(weight-goodweight+1));
    else if(weight >= 1.8*goodweight)
        printf("我对您深表同情。。。");
     
        getchar();
        getchar();
        return 0;
}


还是不能运行。。
错误    4    error C2059: 语法错误 : “)”      12    work1
2011-10-16 22:53
embed_xuel
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:58
帖 子:3845
专家分:11385
注 册:2011-9-13
得分:0 
回复 4楼 ai_44
你能再细心点吗?

总有那身价贱的人给作业贴回复完整的代码
2011-10-16 22:55
lansane
Rank: 2
等 级:论坛游民
帖 子:17
专家分:58
注 册:2011-5-19
得分:1 
scanf("%f\n",&high);把每个scanf里面的\n删除吧。
else if((weight >= 0.9*goodweight)&&(weight <= 1.1*goodweight))
        printf("恭喜您,您的体重正常,请保持",);  //明显多个逗号

2011-10-16 23:10
ai_44
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2011-9-26
得分:0 
我真粗心。。。
2011-10-16 23:16
绿茶盖儿
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
威 望:1
帖 子:363
专家分:1852
注 册:2011-9-3
得分:1 
回复 3楼 laoyang103
你这句话突然提醒了我,仔细想想,用else if确实能提高运行速度,看来以后要注意自己的代码风格,不仅要实现功能,还要提高代码效率
2011-10-16 23:31
星辰雁
Rank: 4
等 级:业余侠客
威 望:1
帖 子:93
专家分:275
注 册:2011-9-10
得分:1 
回复 3楼 laoyang103
大有收获(else if确实能提高运行速度),谢谢

不要认为CPU运算速度快就 把所有的问题都推给它去做,程序员应该将代码优化再优化,我们自己能做的决不要让CPU做 ,因为CPU是为用户服务的,不是为我们程序员服务的!
2011-10-16 23:40



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-352624-1-1.html




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

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