Average and median giving ridiculous answers

(all information given is biased off the input of 5 students and each student watching 1, 2, 3, 4 and 5 respectfully) hello i am just starting c++ and am having trouble with my code more specifically getting the average and median average gives a crazy answer usually in the hundreds of thousands and the median just gives a wrong answer so i was wonder what i did wrong all if it seems correct but i still get vastly wrong awnsers.
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
  	
#include <iostream>
#include <iomanip>
using namespace std;

double median(int *, int);
int mode(int *, int);
void getMovieData(int *, int);
void selectionSort(int [], int);
double average(int *, int);

int main()
{
	double average1, median1;
	int *movies, students, mode1;


	cout << "How many students were surveyed? ";
	cin	 >> students;
	movies = new int[students];
	
	getMovieData(movies, students);
	selectionSort(movies, students);
	
	average1 = average(movies, students);
	
	median1 = median(movies, students);
	
	mode1 = mode(movies, students);
	
	cout << "Here are the results for the number of movies college students watch in a month.\n";
	cout << fixed << showpoint << setprecision(2);
	cout << "The average is " << average1 << endl;
	cout << "The median is " << median1 << endl;
	cout << "The mode is " << mode1 << endl;
	
	delete [] movies;
	movies = 0;
	
	return 0;
}


void getMovieData (int *array, int size)
{
	cout << "How many movies did each student see \n";
	for (int index = 0; index < size; index++)
	{
		cout << "Student " << (index + 1) << ": ";
		cin >> *(array + 1);
	}
}

void selectionSort(int array[], int size)
{
	int startScan, minIndex, minValue;
	
	for (startScan = 0; startScan < (size - 1); startScan++)
	{
		minIndex = startScan;
		minValue = array[startScan];
		for(int index = startScan + 1; index < size; index++)
		{
			if (array[index] < minValue)
			{
				minValue = array[index];
				minIndex = index;
			}
		}
		array[minIndex] = array[startScan];
		array[startScan] = minValue;
	}
}

double average(int *array, int size)
{
	double sum = 0;
	for (int index = 0; index < size; index++)
	{
		sum += *(array +index);
	}
	return sum / size;
}

double median(int *array, int size)
{
	int middle = (size - 1) / 2;
	double median;
	
	if(size % 2 == 0)
	{
		median = (*(array + middle) + *(array + (middle + 1))) / 2;
	}
	
	else
	{
		median = *(array + middle);
	}
	return median;
}

int mode(int *array, int size)
{
	int mode, max, count;
	count = max = 0;
	
	for (int index = 0; index < size; index++)
	{
		count++;
		if (*(array + index) < *(array + index + 1))
		{
			if (count > max)
			{
				mode = *(array + index);
				max = count;
			}
			count = 0;
		}

		}
}
Two problems I see:

1. In getMovieData() you put all input in the second place of the array cin >> *(array + 1);

2. int mode(int *array, int size) does not return a value. How you could run it?

for the first one i feel like that is correct for what im trying to do (so that the information given is for the correct student)

second i think it may be the program im using i really need to remember to return but it wasn't needed in this case.
for the first one i feel like that is correct for what im trying to do

No, that's a 1 you're adding, so you always get the second student.
what you want is:
1
2
3
  cin >> (array + index);
// Or more intuitively:
  cin >> array[index];


i really need to remember to return but it wasn't needed in this case.

Why not? What value do you think is being returned by mode() and stored in mode1 at line 29?
Topic archived. No new replies allowed.