我目前正在尝试使用 C++。到目前为止,我已经学会了制作一个程序,该程序允许我输入 10 个变量以及 5 个已经赋值的变量,然后找到这些数字的平均值。但是我无法弄清楚如何做到这一点,我为数组创建了一个 for 循环,但似乎没有找到答案平均值。以下代码有什么问题?这是我到目前为止所拥有的:
#include <iostream>
using namespace std;
int cole[10];
int sum = 0;
int main()
{
int a = 10;
int b = 10;
int c = 10;
int d = 10;
int e = 35;
cout << "Please input ten numbers, one at a time" << endl;
cin >> cole[0];
cin >> cole[1];
cin >> cole[2];
cin >> cole[3];
cin >> cole[4];
cin >> cole[5];
cin >> cole[6];
cin >> cole[7];
cin >> cole[8];
cin >> cole[9];
cout << "There will now be 5 assigned variables, so that we have 15 variables" << endl;
for(int x = 0; x < 10; x++ )
{
int sum = 0;
cout << cole[x] << " ";
sum += cole[x];
cole[x]++;
}
sum += cole[0];
cole[0]++;
cout << "and " << a << " " << b << " " << c << " " << d << " " << e << endl;
cout << "The average of these numbers is: ";
sum = sum + a + b + c + d + e;
cout << sum / 15;
}
提前致谢