C++ 为什么这些函数会截断返回值? 注意下面有作业。 编辑:

C++ 为什么这些函数会截断返回值? 注意下面有作业。 编辑:,c++,function,arithmetic-expressions,truncated,C++,Function,Arithmetic Expressions,Truncated,取出无用的信息 很明显,这是一个家庭作业,除了我函数中的计算之外,所有的事情看起来都是正确的 如何返回非截断值 float hat(float weight, float height) { return (weight/height)*2.9; } float jacket(float weight, float height, int age) { double result = (height * weight) / 288; /*now for every 10

取出无用的信息

很明显,这是一个家庭作业,除了我函数中的计算之外,所有的事情看起来都是正确的

如何返回非截断值

float hat(float weight, float height) {
    return (weight/height)*2.9;
}
float jacket(float weight, float height, int age) {
    double result = (height * weight) / 288;
    /*now for every 10 years past 30 add (1/8) to the result*/
    if((age - 30) > 0){
        int temp = (age - 30) / 10;
        result = result + (temp * .125);
        //cout<<"result is: "<<result<<endl;
    }
    return result;
}

float waist(float weight, int age) {
    double result = weight / 5.7;
    /*now for every 2 years past 28 we add (1/10) to the result*/
    if((age - 28) > 0){
        int temp = (age - 28) / 2;
        result = result + (temp * .1);
    }
return result;}
float帽子(浮子重量、浮子高度){
返回(重量/高度)*2.9;
}
浮子夹套(浮子重量、浮子高度、内部尺寸){
双倍结果=(身高*体重)/288;
/*现在,在过去的30年中,每10年将结果加上(1/8)*/
如果((30岁)>0){
内部温度=(30岁)/10岁;
结果=结果+(温度*.125);

//cout设置
固定

  // Output data //
  cout << fixed;
  cout << "hat size: " << setprecision(2) << hat(weight, height) << endl;
  cout << "jacket size: " << setprecision(2) << jacket(weight, height, age) << endl;
  cout << "waist size: " << setprecision(2) << waist(weight, age) << endl;
//输出数据//

cout
cout你输入的顺序不正确。学会使用调试程序我刚发现。现在这些值正在向下或向上截断到最接近的值。我将更新这个问题。我们提出这个问题是有原因的。对于家庭作业问题,你的问题没那么糟糕,但你提供了太多细节。人们还有其他事情要做阅读你的家庭作业的复杂细节。将其归结为要点-你正在接受输入,并且你在计算和/或显示输出时遇到困难。编写一个新的程序来实现这一点。如果在那之后你有同样的问题,请将代码发布给大家看。好的,在这种情况下,我应该删掉它找出所有与截断值无关的内容,明白了。
cout << "hat size: " << setprecision(2) << hat(weight, height) << endl;