看看这个C++程序错在哪

来源:百度知道 编辑:UC知道 时间:2024/06/07 20:32:33
这个C++程序哪里错了。输出结果错误
悬赏分:5 - 离问题结束还有 14 天 2 小时
#include <iostream.h>

class bmi //BMI算法的肥胖公式

{
private:
float high,weight;

public:
bmi (float h,float w);//构造函数,公有成员与私有成员参数名不要一样
float Getbmi();//BMI算法的肥胖公式
};//类定义结束

bmi::bmi (float h,float w)//给出类的函数成员
{high=h,weight=w;}

float bmi::Getbmi()
{return weight/(high*high);} //BMI算法的肥胖公式

void main() //主函数开始
{
float high,weight,result;
cout << "Please enter you high and weight:" << endl;
cin >>high,weight;

bmi b(high,weight);
result=b.Getbmi();
cout << "The result is:" <<result<< endl;
}

。。。。。。。。。。。。。。
没看见

结果正确

bmi::bmi (float h,float w)//给出类的函数成员
{high=h,weight=w;}

赋值语句应该分开写,“{high=h,weight=w;} ”应该改成:
{high=h;weight=w;}

另外cin >>high,weight; 可能也有点问题