我有一些作业中的问题,我无法找到答案。C++语句没有影响
我必须做一个简单的程序,解决了一个数学问题,但它并不COMP
这是代码:
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
int a, b, FirstA;
int result = 0;
FirstA = a;
// The sum of the cubes between a and b: (a^3 + (a + 1)^3 + .. + (b + 1)^3 + b^3)
while (cin >> a >> b) {
for (a; a <= b; a++) {
result = result + pow(a,3);
}
cout << "suma dels cubs entre " << FirstA << " i " << b << ": " << result << endl;
}
}
它给人的错误是这样的:
program.cc: In function ‘int main()’:
program.cc:23:15: error: statement has no effect [-Werror=unused-value]
for (a; a <= b; a++) {
所有警告被视为错误。
我该怎么办?
不使用'的std :: istream的::运算符>>'。使用'std :: getline()'代替获取一行用户输入,然后在事实之后解析该行。 –
@Coeus虽然通常的做法是,如果控件到达大括号,'return 0'隐含在'main'中。 – kemotoe