#include <iostream>
usingnamespace std;
int n;
int m[25];
int i;
int average;
int main()
{
cout << " Introduce one value between 0 and 20: \n";
cin >> n;
{
for (i=0;i<n;i++)
{
cout << " Introduce grades of students between 0 and 20:";
cin >> m[i];
}
}
average = (m[i]/n);
cout << " The average of students is : " << average << endl;
system("PAUSE");
return EXIT_SUCCESS;
}
you declared i inside the for loop. After that loop is done i is no longer in scope, so calling m[i] is invalid. Even if it was valid, it would only assign the value of ONE element divided by n to average. For this to work with an array you'd have to add each element in the array, then divide by the number of elements and assign that value to average. Something like this:
1 2 3 4 5 6
int sum = 0;
for (int i = 0; i < n; i++)
sum += m[i];
average = sum/n;