### average

 ``123456789101112131415161718192021222324252627282930`` ``````#include using namespace 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> m[i]; } } average = (m[i]/n); cout << " The average of students is : " << average << endl; system("PAUSE"); return EXIT_SUCCESS; } ``````

why my average didn't go to output ???
To output the average you have to get the sum of all array elements.:)
sum = (m[i]++);

it ?
 ```-- declare total -- add each element value to total -- divide total by number of elements in array ```
Last edited on
 @dioing sum = (m[i]++); it ?

No.
You have now two attempts.:)
iHutch105, i now what to do , but don't how !
i'm very begginer :/
vlad from moscow , i'm in such exercises a few hours ...
 ``12345678`` `````` int sum = 0; for ( i = 0; i < n; i++ ) { sum += m[i]; } average = sum / n; cout << " The average of students is : " << average << endl; ``````
Last edited on
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:

 ``123456`` ``````int sum = 0; for (int i = 0; i < n; i++) sum += m[i]; average = sum/n;``````
one big thank you ! I'm realy bad in c++ !
Topic archived. No new replies allowed.