标题:求教:请问以下小工程C语言结构体中编译问题应如何修改代码(too many init ...
只看楼主
q22314731805
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2018-12-30
结帖率:0
已结贴  问题点数:20 回复次数:1 
求教:请问以下小工程C语言结构体中编译问题应如何修改代码(too many initializers & term does not evaluate
.cpp中
#include <stdio.h>
#include "Codelab9_1.h"

double StandardWeight(char (pUserData.cGender), double (pUserData.dHeight));
int WeightStatus(double (pUserData.dStandardWeight), double (pUserData.dActualWeight));
void OutputResult(struct CheckInfoStru pUserData);
 int main() {

    printf("请输入您的身高为: *cm");
    scanf("%lf",&(pUserData.dHeight));
    printf("如果您的性别为男,请输入M;若为女,请输入F;");
    (pUserData.cGender)=getchar();
    printf("请输入您的体重");
    scanf("%lf",&(pUserData.dActualWeight));
    StandardWeight( pUserData.cGender,  pUserData.dHeight);
    WeightStatus( (pUserData.dStandardWeight),  (pUserData.dActualWeight));   
    OutputResult( pUserData);
    return 0;
}

double StandardWeight(char (pUserData.cGender), double (pUserData.dHeight)) {
    double mstanderweight,fstangerweight;
    if((pUserData.cGender)=='M')    {
    mstanderweight=(pUserData.dHeight-100)*0.9;
    return mstanderweight;
    }
    if((pUserData.cGender)=='F')    {
    fstanderweight=((pUserData.dHeight)-100)*0.9-2.5;
    return fstanderweight;
    }

}


int WeightStatus(double (pUserData.dStandardWeight), double (pUserData.dActualWeight) ) {
    (pUserData.dStandardWeight)=StandardWeight;
    double a,b,one,two,three,five;
    a= (pUserData.dStandardWeight);b=(pUserData.dActualWeight);
    one=(pUserData.dStandardWeight)*0.1;
    two=(pUserData.dStandardWeight)*0.2;
    three=(pUserData.dStandardWeight)*0.3;
    five=(pUserData.dStandardWeight)*0.5;
    if(a<b-one) {
    return 0;
    }
    if(a>=b-one && a<=b+one) {
    return 1;
    }
    if(a>b+one && a<=b+two) {
    return 2;
    }
    if(a>b+two && a<=b+three) {
    return 3;
    }
    if(a>=b+three && a<b+five) {
    return 4;
    }
    if(a>=b+five) {
    return 5;
    }
}

void OutputResult(struct CheckInfoStru pUserData)
{if((pUserData.cGender)=='f') {
    printf("您的身高为:%.2lf, 性别:女,体重:%.0lfkg",(pUserData.dHeight),(pUserData.dActualWeight));
    printf("您的标准体重应为:%lf\n",(pUserData.dStandardWeight)=StandardWeight);}
    int num=WeightStatus;
    if(WeightStatus==0) {
        printf("您的体重情况为:太廋\n");
    }
    if(num==1) {
        printf("您的体重情况为:正常\n");
    }
    if(num==2) {
        printf("您的体重情况为:超重\n");
    }     
    if(num==3) {
        printf("您的体重情况为:轻度肥胖\n");
    }
    if(num==4) {
        printf("您的体重情况为:中度肥胖\n");
    }
    if(num==5) {
        printf("您的体重情况为:重度肥胖\n");
    }
    (pUserData.dOverweightPercent)=((pUserData.dActualWeight)-(pUserData.dStandardWeight))/(pUserData.dStandardWeight);
    if((pUserData.dOverweightPercent)<0) {
    printf("您的体重 低于 标准体重 x%%.2lf\n",(pUserData.dOverweightPercent)=-(pUserData.dOverweightPercent)*100);
    }
    if((pUserData.dOverweightPercent)>0) {
    printf("您的体重 高于 标准体重 x%%.2lf\n",(pUserData.dOverweightPercent)=(pUserData.dOverweightPercent)*100);
    }
}
.h中
#ifndef CODEFORLAB9_1_H  


#define CODEFORLAB9_1_H

//各种体重状态
enum {TOO_SLIM = 0, NORMAL, OVER_WEIGHT,
        MILD_OBESITY, MODERATE_OBESITY, TOO_FAT };

struct CheckInfoStru{
    char cGender;    //性别
    double dHeight;    //身高
    double dActualWeight;//实际体重
    double dStandardWeight;//标准体重
    double dOverweightPercent; //超重比例
    int nResult;    //体重检测结果
};
struct CheckInfoStru pUserData;

#endif
编译问题
Compiling...
cal.cpp
C:\Users\asus\Desktop\Win10_VC6.0_Chinese 2\2018123102\cal.cpp(5) : error C2078: too many initializers
C:\Users\asus\Desktop\Win10_VC6.0_Chinese 2\2018123102\cal.cpp(6) : error C2078: too many initializers
C:\Users\asus\Desktop\Win10_VC6.0_Chinese 2\2018123102\cal.cpp(6) : warning C4244: 'initializing' : conversion from 'double' to 'int', possible loss of data
C:\Users\asus\Desktop\Win10_VC6.0_Chinese 2\2018123102\cal.cpp(16) : error C2064: term does not evaluate to a function
C:\Users\asus\Desktop\Win10_VC6.0_Chinese 2\2018123102\cal.cpp(17) : error C2064: term does not evaluate to a function
C:\Users\asus\Desktop\Win10_VC6.0_Chinese 2\2018123102\cal.cpp(22) : error C2448: '<Unknown>' : function-style initializer appears to be a function definition
C:\Users\asus\Desktop\Win10_VC6.0_Chinese 2\2018123102\cal.cpp(36) : error C2448: '<Unknown>' : function-style initializer appears to be a function definition
执行 cl.exe 时出错.

cal.obj - 1 error(s), 0 warning(s)




[此贴子已经被作者于2018-12-30 16:50编辑过]

搜索更多相关主题的帖子: cpp double printf return Users 
2018-12-30 16:48
豆豆的滴
Rank: 9Rank: 9Rank: 9
来 自:湖南
等 级:贵宾
威 望:33
帖 子:368
专家分:1087
注 册:2018-5-7
得分:20 
初始化太多。。。。
可以认真的改一下代码

2018-12-30 22:25



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




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

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