1
当我声明int weight
,然后输入一个双值165.1
第二cin >> height;
不起作用,并没有任何错误消息。你能告诉我为什么吗?关于在c + + cin的问题
已使用VS2010控制台应用程序。
#include <iostream>
using namespace std;
const double lbs_to_kg = 2.2046, inches_to_meter = 39.370;
int main()
{
int weight, height;
double kilograms, meters;
cout << "\nEnter weight in pounds: ";
cin >> weight;
kilograms = weight/lbs_to_kg;
cout << "\nEnter height in inches: ";
cin >> height;
meters = height/inches_to_meter;
cout << "\nYour BMI is approximately "
<< "\nbody fat ratio is "
<< kilograms/(meters * meters)
<< ". Under 25 is good."
<< endl;
}
output:
Enter weight in pounds: 165.1
Enter height in inches:
Your BMI is approximately
body fat ratio is 1.57219e-013. Under 25 is good.
嗯..这将是一个有趣的身体脂肪比例。 – 2010-06-24 02:09:51
@比利:这是浮点饮食。你花很多时间试图理解程序中浮点运算的效果,你忘记了一个月的时间。 – 2010-06-24 02:22:10