hi to all,
i want to write a program, which, when user inputs a number, array of same size is made, and user then initializes the elements of an array, and at the end, we average those inputs(numbers)
code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
#include <iostream>
using namespace std;
int main()
{
int n;
cout << "Enter the number of values to average: ";
cin >> n;
int arr[n];
for(int cnt = 0; cnt < n; ++cnt)
{
int m;
arr[cnt] = m;
cout << "[" << cnt << "] = ";
cin >> m;
}
cout << "Average = " << endl;
}
|
i get these errors :
...cpp(12) : error C2057: expected constant expression
...cpp(12) : error C2466: cannot allocate an array of constant size 0
...cpp(12) : error C2133: 'arr' : unknown size
of course as you can see, i havent made average computation, because i dont know how to make "mathematical operations", i do between arrays, but not like this, so if anyone could help me out with that, or give me link to tutorial mabe, ill be glad :)
ty in advance for all the help