Help needed

Hello so I'm having an issue with this program I set the user to input up to 20 grades once the user has inputted let's say 8 grades they can exit if the like or continue imputing grades. After the user has done all that the program is suppose to calculate the mean and median of the numbers they imputed. Now the problem is that I don't know how to calculate the mean I get the median perfectly but I'm having issues getting the mean.


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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include<iostream>
#include<string>


using namespace std;



int  main(void)
{

int x, i, sum, suml, counter, inner, outer, mean;
const int f=20, l=0;
int igrade[f];
x=0;
counter=0;


cout<<"Enter you first grade: ";
cin>>igrade[x];
while (x<20 && igrade[x]>0)
{counter++;  x++;

cout<<"Enter your next grade or type (-esc) to get results: ";
cin>>igrade[x];
}
cin.ignore(1);


for(i=0;i<=x;i++)
{
suml= i / counter;// Here is were I try o calculate the mean but here is the reouble????
}

//Sort

for (outer = 0; outer < x+1; outer++)

for (inner = 0; inner < (x+1)-1; inner++ )

if (igrade[inner] > igrade[inner+1])

swap(igrade[inner], igrade[inner+1]);

sum=(x+1)/2;

cout<<"MEDIAN= "<<igrade[sum];

cout<<endl<<endl;

cout<<"\nMean value is "<<suml<<endl;

system("pause");

return 0;

}
Topic archived. No new replies allowed.