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