此(C )代码有什么问题吗?如果是这样,有人可以告诉我我在哪里出错
Is there anything wrong with this (c++)code? if so can anybody tell me where I went wrong?
我是C 的新手,正在练习。我使用CodeBlocks IDE。
#include <iostream>
using namespace std;
int main() {
double f;
double m;
int counter;
counter = 0;
for (f = 1.0, f <= 100.0, f++) { // error: expected primary-expression before ')'
m = f / 3.28;
cout << f << " feet is " << m << " meters!n done";
counter++;
if (counter == 10) {
cout << "n";
counter = 0;
}
}
cin.ignore();
cin.get();
return 0;
}
每次我将其放在IDE中时,我会收到以下错误:
error: expected primary-expression before ')' token
有人可以将我指向正确的方向吗?
您需要用semicolons而不是逗号分开for
语句中的子句。
另外,声明for
内的循环变量是清洁的:
for(double f=1.0; f<=100.0; f++) {
...
}
您的循环语句被逗号错误地分开。使它们半彩:
for (f = 1.0; f <= 100.0; f++) {
}
for
循环需要在语句之间的半隆,因此应该是:
for(f=1.0; f<=100.0; f++)
return 0;
}
您的语句不正确:
for(f=1.0, f<=100.0, f++)
应该是:
for(f = 1.0; f <= 100.0; f += 1) // for(initial value; continuation condition; increment)
本质上,您需要将这些逗号更改为分号。
相关文章:
- C++我需要了解在哪里使用指针和双指针
- 在哪里放置我的函数?进入我的母语 Gui 还是进入我的演示者?
- 如何告诉本机节点模块所需的dll存储在哪里?
- 我的重复检查代码中的错误究竟在哪里?
- CLion 是否支持自定义输入?如果是,我在哪里输入它们?
- 我想知道变焦和轨道在哪里出了问题
- 我在哪里修复有关模板的C++代码?
- 关于这个在 Linux 上使用 gcc 编译的程序中的 vtable,nm 告诉我什么?
- >= <= 没有按照我使用它们的方式工作,我在哪里搞砸了?
- 编写 Windows 桌面应用程序时,我应该在哪里跟踪我的窗口句柄?
- 我的调试器说我有一个隔离错误错误,但无法告诉我在哪里,在非常特殊的情况下发生
- 此(C )代码有什么问题吗?如果是这样,有人可以告诉我我在哪里出错
- 在哪里保存我的C++库?(乌班图)
- 告诉gnu autotools我新安装的库在哪里(使用PKG_CONFIG?)
- 我应该在哪里实现我的类方法
- 如果我知道数据在哪里,我能知道什么关于数据,例如0xffffffff7fffd9d8与0x10019c1e0
- 我应该在哪里保存我的着色器代码
- 我如何告诉cmake在哪里输出构建数据?
- 在哪里写我的代码在main.cpp或在mainwindow.cpp
- 在哪里把我的dll文件使用f#