Min of array always setting to 0

Hello, this is my first post so I hope everything will be proper.
Anyways, 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.

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
#include <iostream>
#include <string>
using namespace std;

const int TOTAL_TESTS = 15;
int numTests[TOTAL_TESTS], testScores[TOTAL_TESTS];
int maximum, minimum;
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];
	for(int i = 1; i < TOTAL_TESTS; i++)
	{
		if(testScores[i] < minimum)
			minimum = testScores[i];
	}
	maximum = testScores[0];
	for (int i = 1; i < TOTAL_TESTS; i++)
	{
		if(testScores[i] > maximum)
			maximum = testScores[i];
	}
	cout<<"The maximum score is: "<<maximum<<endl<<endl;
	cout<<"The minimum score is: "<<minimum<<endl<<endl;
	
	return 0;
} 

Now I've gotten the maximum value to work, but for some reason the minimum value always shows it's equal to 0. Can someone explain what I'm doing wrong? Thanks in advance!
You enter numTests[TOTAL_TESTS] values but then search from TOTAL_TESTS values.
Oh I see! It's working now, thanks a ton
So now I'm at the part to get the median of the values. Problem is I've never dealt with medians. Can I get maybe an example and an explanation to help me? I'm really in the dark on this area.
The median is really a concept from mathematics, rather than C++ programming. Fortunately, it's fairly straightforward to understand. See for example this page: http://www.mathsisfun.com/median.html
Forgive me, I wasn't very clear. I know the concept of medians, I simply do not know how to implement them into my program. I've been searching around, and I believe you must sort the numbers first, but I don't know how to do that either. What I need help with is how to write a code inside my program that will find the median. Please help
So actually, what you really need to know is how to sort your array.
Well, luckily, C++ has a built-in sort capability:
http://www.cplusplus.com/reference/algorithm/sort/

However, should you feel the need to construct the code for sorting yourself, you might look over the article here, bearing in mind that sorting is an entire topic in its own right: http://www.cprogramming.com/tutorial/computersciencetheory/sorting1.html
Last edited on
<algorithm> has more than one sorting algorithm. Some do less work than std::sort, yet suffice for finding the median. For homework, I would try to guess what std::nth_element() does, and write similar code self.
Topic archived. No new replies allowed.