最后一个 for
循环有问题。想要数组值的总和。
#include<iostream>
using namespace std;
// Arrays
int main()
{
const int numEmploye = 6;
int horas[numEmploye];
int total = 0;
for (int i = 0; i < numEmploye; i++) {
cout << "entre las horas trabajadas por el empleado " << i + 1 << ": ";
cin >> horas[i];
}
for (int i = 0; i < numEmploye; i++) {
cout << horas[i] << endl;
}
for (int i = 0; i < numEmploye; i++){
cout << total += numEmploye[i];
}
system("Pause");
return 0;
}
最佳答案
您正在输出 += 运算符的返回值。您还为数组使用了错误的变量。
for (int i = 0; i < numEmploye; i++){
total += horas[i];
}
cout << total << endl; // endl flushes the buffer
关于c++ - for循环中的数组加法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33092881/