无法让程序在C++输出正确的结果
Can't get program to output the right result in C++
我被要求制作这个程序来计算一个人的体重指数。由于我注意到METRIC
未运行,US_IMPERIAL
不完整。我无法算出错误,因为无论我输入什么数字,结果都是0。
#include <iostream>
using namespace std;
float METRIC (int b, int c)
{
float res;
res = b / c / c * 10000;
return res;
}
float US_IMPERIAL (float d, float e)
{
float resu;
resu = (d / e / e) * 703;
return resu;
}
int main ()
{
cout << "Hello. BMI CALCULATOR!" << endl <<
"Press 1 for METRIC or 2 for US imperial: ";
int a;
cin >> a;
if (a == 1) {
cout << "Enter your weight in KILOGRAMS (KG): ";
int b;
cin >> b;
cout << "Now enter you height in CENTIMETERS(CM): ";
int c;
cin >> c;
cout << "Your BMI is: " << METRIC (b, c);
} else if (a == 2) {
// not yet implemented
} else {
cout << "Error.";
}
return 0;
}
在METRIC
函数中,表达式b / c / c * 10000
是全整数表达式。如果你想要分数,那就不太好用了。
我建议您将参数b
和c
转换为浮点变量。
相关文章:
- Fmod 函数清楚地输出一个预期的双精度值,但 if(fmod == 预期的双精度值)的计算结果不是 true
- 我的输出结果是 0 英寸C++.可能是什么问题
- 无法让程序在C++输出正确的结果
- C++ 字符串的排列,输出的结果小于或等于字符串的长度
- cuSparse (cusparseDcsrgemm) 中的矩阵乘法输出错误的结果
- 二维数组的输出结果
- Web 编译器输出奇怪的结果
- 该程序应该创建一个带有结果的输出文件,但文件中没有任何内容
- C++ 循环以在表中输出结果
- 执行 CUDA 内核时黑屏C++输出正确的结果
- infix/postfix/prefix程序.想要使用我的printresult()函数打印结果.需要帮助获得输出
- 输出结果时如何将参数化测试合并为一个
- 在将数组与字符数组进行比较后需要帮助输出一次结果
- 二项式系数程序输出错误的结果,如果输入是大的(C++)
- 如何将atof的结果输出为1.0而不是1
- 正在读取C++中的二进制文件,并将结果输出为hexdump
- 将Botan加密结果输出到QDomDocument,反之亦然
- 混合推力和cuBLAS意想不到的结果输出
- visual studio 2010-C++模板:使用MInGW获取错误的结果(输出)
- 为什么结果输出为 1