解决方案在第 25 行执行错误'out of bounds'
The solution is executed with error 'out of bounds' on the line 25
在编译过程中收到越界错误,尝试的替代方法仍然相同。 它说第 25 行发生错误,这只是边界内的 CIN 语句。 我到底哪里出错了。叮叮当当,调试器正在生成此错误。
int main ()
{
int n;
cin >> n;
int work[n];
for (int j = 1; j <= n; j++)
{
cin >> work[j];
}
int i = -2, j = -1, k = 0, l = 0;
int ch = 0, bi = 0, ba = 0;
while (l < n)
{
ch = ch + work[i+3];
l++;
bi = bi + work[j+3];
l++;
ba = ba + work[k+3];
l++;
i+=3;
j+=3;
k+=3;
}
if (ch > bi && ch > ba)
cout << "chest" << endl;
else if (bi > ch && bi > ba)
cout << "biceps" << endl;
else
cout << "back" << endl;
return 0;
}
这是错误的:
for (int j = 1; j <= n; j++)
{
cin >> work[j];
}
数组索引从 0 到 size-1(包括(。更改为:
for (int j = 0; j < n; j++)
{
cin >> work[j];
}
更新:必须添加嵌套的if和else才能使其工作,现在它可以在边界内工作
while (l < n)
{
ch = ch + work[i+3];
l++;
if(l<n)
{
bi = bi + work[j+3];
l++;
}
else
break;
if(l<n)
{
ba = ba + work[k+3];
l++;
}
else
break;
i+=3;
j+=3;
k+=3;
}
相关文章:
- Usages of std::move
- 使用 [] 运算符时"binding reference of type discards qualifiers"
- 如何处理 c++ 中类实现中的"invalid use of non-static data member"?
- 具有变量Number of Arguments的std::函数的矢量
- Capacity of a deque
- Deprecation of _writeBarrier()
- constexpr begin of a std::array
- 如何调整 std::vector of Eigen::MatrixXd 的大小
- C++ "error: invalid use of void expression"
- 我看到"use of undeclared identifier"错误,有人可以告诉我如何解决它吗?
- 赛通"Cannot take address of memoryview slice"
- C++ Version Of Double.longBitsToDouble
- 收到错误"invalid use of non-static data member 'stu::n' "
- 解决方案在第 25 行执行错误'out of bounds'
- C++ 错误:"cannot find bounds of current function"
- 如何处理C++'index out of bounds error'?
- Opengl "Cannot find bounds of current function"
- 泛型"out of bounds"、"past end"迭代器
- 代码::块调试器,"Cannot find the bounds of current function"
- Bounds of std::string::find_first_of