我不断收到错误,我不知道我错过了什么。这只是我的第一个编程类,所以它可能非常简单,我没有看到。帮帮我? :)为什么我会得到“错误:'<<'标记之前预期的初级表达式。”
#include <iostream>
using namespace std;
const float METERS_PER_INCH = 39.3700787;
const float METERS_PER_FOOT = 3.2808399;
const float METERS_PER_YARD = 1.09361;
int main()
{
int yards;
int feet;
int inches;
int totalMeters;
cout << "Enter a length in meters: ";
cin >> totalMeters;
cout << endl;
cout << "The total length is " << endl;
<< totalMeters * METERS_PER_YARD << "yards;"
<< yards * METERS_PER_FOOT << "feet;"
<< feet * METERS_PER_INCH << "inches;"
<< endl;
return 0;
}
在'endl;'后面有一个分号,''总长度'','<<'之前没有新的'cout'。在尝试打印从中派生的值之前,您也不要设置“码”或“英尺”。 – 2014-09-12 18:23:16
我不确定你评论的最后部分是什么意思? (很明显,我是这个新的。哈) – Ally 2014-09-12 18:27:57
什么价值分配给“码”?答:没有价值。因此打印'yard * METERS_PER_FOOT'将打印一个不确定的(准随机)值。 “脚”也一样。而且你甚至不使用变量'inches'。 – 2014-09-12 18:29:08