我一直收到错误,我不知道自己错过了什么。这只是我的第一个编程类,所以它可能是我看不到的非常简单的东西。救命? :)
#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;
}
答案 0 :(得分:2)
将您的上一个cout
更改为:
cout << "The total length is " << endl
<< totalMeters * METERS_PER_YARD << "yards;"
<< yards * METERS_PER_FOOT << "feet;"
<< feet * METERS_PER_INCH << "inches;"
<< endl;
区别在于;
之后删除了endl
。
使用分号,cout
的第一行是一个语句,因此编译器会在下一行查找新语句。语句不能只以<<
开头,因为它是一个二元运算符 - 它也需要左侧的表达式。