所以我得到了这个C ++ Primer Plus,并且我需要编写一个程序来获取一个人的BMI,我需要以英尺和英寸为单位要求高度,然后转换成英寸,然后问这个人他们的体重(以磅为单位)并将其转换为千克,这就是它
我提前感谢帮助=)
继续收到此错误 严重性代码描述项目文件行抑制状态 错误C2086'双倍英寸':重新定义ConsoleApplication14
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
const double inchesFactor = 12;
const double metersFactor = 0.0254;
const double massFactor = 2.2;
double height;
double weight;
double BMI;
double inches;
double mass;
double meters;
cout << "Enter height " << flush;
cin >> height;
cout << "Enter weight " << flush;
cin >> weight;
double inches = (height * inchesFactor);
double mass = weight / massFactor;
double meters = inches / 0.5;
double BMI = mass / meters;
cout << "Your BMI is " << BMI << endl;
答案 0 :(得分:0)
以下代码运行,您需要删除额外的双打。我删除了#include "stdafx.h"
因为我没有使用VS,但你可以把它放回去
#include <iostream>
using namespace std;
int main()
{
const double inchesFactor = 12;
const double metersFactor = 0.0254;
const double massFactor = 2.2;
double height;
double weight;
double BMI;
double inches;
double mass;
double meters;
cout << "Enter height " << flush;
cin >> height;
cout << "Enter weight " << flush;
cin >> weight;
inches = (height * inchesFactor);
mass = weight / massFactor;
meters = inches / 0.5;
BMI = mass / meters;
cout << "Your BMI is " << BMI << endl;
return 0;
}
答案 1 :(得分:0)
让我们来看看你的代码。在这里,您声明了一堆import packA.A;
类型的变量:
double
然后你要求用户输入身高和体重:
double height;
double weight;
double BMI;
double inches;
double mass;
double meters;
在这里你做了大量的计算:
cout << "Enter height " << flush;
cin >> height;
cout << "Enter weight " << flush;
cin >> weight;
当你写double inches = (height * inchesFactor);
double mass = weight / massFactor;
double meters = inches / 0.5;
double BMI = mass / meters;
时,你告诉编译器&#34;我想要一个类型为double inches = (height * inchesFactor);
的 新 变量使用名称double
,我想将其设置为inches
的值。但是你不能创建一个名为(height * inchesFactor)
的新变量,因为你之前已经声明了一个带有该名称的变量。
如果你省略了类型而只是写inches
,那么你就是在告诉编译器:&#34;我想设置变量inches = (height * inchesFactor);
, 我是&#39; ve在其他地方宣布 ,价值为inches
。
因此,要修复代码,请将上面的最后一段代码替换为:
(height * inchesFactor)
因为您之前已经宣布过inches = (height * inchesFactor);
mass = weight / massFactor;
meters = inches / 0.5;
BMI = mass / meters;
,inches
,mass
和meters
。