Median of arrays

Hi there, I'm working on this assignment that requires the user to enter up to 15 "test grades" in an array and find the min, max, median, and average of the entered values. Problem is I don't know how to implement medians into code, and I have no idea where to start. Can I get maybe an example and an explanation to help me? I'm really in the dark on this area. Here's what I have so far:
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
#include <iostream>
#include <string>
using namespace std;

const int TOTAL_TESTS = 15;
int numTests[TOTAL_TESTS], testScores[TOTAL_TESTS], maximum, minimum, median;
float total, average;
string firstName[TOTAL_TESTS], lastName[TOTAL_TESTS];

int main()
{
	cout<<"Enter the first name of the student: ";
	cin>>firstName[TOTAL_TESTS];
	cout<<endl;

	cout<<"Enter the last name of the student: ";
	cin>>lastName[TOTAL_TESTS];
	cout<<endl;

	cout<<"What is the total number of test scores you will enter? ";
	cin>>numTests[TOTAL_TESTS];
	cout<<endl;
	for(int i = 1; i <= 100; i++)
	{
		if(numTests[TOTAL_TESTS] > TOTAL_TESTS)
		{
			cout<<"Error. Cannot submit more than 15 tests at one time."<<endl;
			cout<<"Please enter the total number of test scores: ";
			cin>>numTests[TOTAL_TESTS];
			cout<<endl;
		}
	}
	for(int i = 0; i < numTests[TOTAL_TESTS]; i++)
	{
		cout<<"Enter your score for test "<<i+1<<": ";
		cin>>testScores[i];		
	}
	cout<<endl;
	
	minimum = testScores[0];
	maximum = testScores[0];
	for(int i = 1; i < numTests[TOTAL_TESTS]; i++)
	{
		if(testScores[i] < minimum)
		{	
			minimum = testScores[i];
		}
		else if(testScores[i] > maximum)
		{
			maximum = testScores[i];
		}
	}
	
	for(int i = 0; i < numTests[TOTAL_TESTS]; i++)
	{
		total += testScores[i];
	}
	average = total / numTests[TOTAL_TESTS];
	average = int(average+ 0.5);
	
	cout<<"The maximum score is: "<<maximum<<endl<<endl;
	cout<<"The minimum score is: "<<minimum<<endl<<endl;
	cout<<"The median score is: "<<endl<<endl;
	cout<<"The average score is: "<<average<<endl<<endl;
	
	return 0;
} 
Last edited on
Topic archived. No new replies allowed.