BMI 计算器错误
BMI calculator bug
我正在尝试做一个基本的 BMI 计算器,当我做它的度量方面时它工作正常,但是,英制方面返回错误的答案。
cout << "What is your weight? ";
cin >> weight;
cout << "What is your height in either inches or meters? ";
cin >> height;
cout << "Is that metric or imperial? Type 1 for metric, or 0 for imperial ";
cin >> unit;
if (unit = 1)
answer = weight / (height * height);
if (unit = 0)
answer = (weight * 703) / (height * height);
cout << "Your BMI is " << answer << endl;
system("PAUSE");
return 0;
根据维基百科,我认为英制的 BMI 等式是
重量(磅)* 703/(高度以英寸平方为单位)
使用 == 测试相等性 not =
你在 if 语句中使用赋值运算符 "=",这两个运算符都将始终返回 true,因为您可以将 "0" 或 "1" 的值分配给单位。
要测试相等性,您必须使用"=="。
这应该可以解决此问题!(:
相关文章:
- 我在c ++矩阵计算器程序中找不到错误
- 野牛/flex:计算器将双精度值解释为整数,所以我添加了 YYSTYPE 双精度 #define 但我有多个编译错误
- RPN计算器c++错误处理和多个运算符
- 我用C++做了一个计算器,但我对"type of calculator"的要求循环了两次。有人可以帮助指出我的错误吗?
- BigInt计算器吐出稍微错误的结果
- C ++指数计算器错误
- BMI 计算器错误
- 分段错误c++十六进制计算器
- C++十六进制计算器运行时错误
- 我正在尝试用C++制作一个费用计算器,我得到了错误C2064:term的计算结果不是一个带1个参数的函数
- C++ - 简单的形状面积计算器返回错误的计算
- C++中的基本计算器错误
- c++计算器atof没有错误,但它在中间一行崩溃(52)
- 2个YUV文件的PSNR计算器使用c++分割错误
- 模块计算器中的错误答案
- 简单计算器尝试重新学习C++.左值错误
- 我正在使用c++制作计算器,但编译器给出了一个错误
- c++等级计算器控制台错误
- 在我的后修复计算器上得到分段错误
- 基本的计算器c++,没有错误,但代码只返回0,不管值是多少