Arrays

Hi,
I have one little problem with my program. It is taking the last test score I enter instead of the lowest test score. Anyone know why it is doing this?
here is my code:
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
#include <iostream>
#include <iomanip>
using namespace std;

//function prototypes
double GetLowest(const double[], int);
void GetScores(double[], int);
double GetTotal(const double[], int);

int main()
{
	const int SIZE = 7;
	double TestScores[SIZE],
		total,
		Lowestscore,
		average;

	cout << fixed << showpoint << setprecision(5);
	cout << "Please Enter 7 test scores: \n";

	GetScores(TestScores, SIZE);

	total = GetTotal(TestScores, SIZE);

	Lowestscore = GetLowest(TestScores, SIZE);

	total -= Lowestscore;

	average = total / (SIZE - 1);

	cout << "The average of the test scores is " << average << ".\n";

	return 0;
}
void GetScores(double score[], int size)
{
	int count;
    //get the 7 test scores
	for (count=0; count < size; count++)
	{
		cout << "Enter test score number " << (count + 1) << ": ";
		cin >> score[count];
	}
}
double GetTotal(const double array[], int size)
{
	double total = 0;

	for (int count = 0; count < size; count++)
		total += array[count];
	return total;
}
double GetLowest(const double array[], int size)
{
	double lowest;

	lowest = array[0];

	for (int count = 1; count < size; count++)
		lowest = array[count];
	return lowest;
}
You forgot do the test in GetLowest().
1
2
3
4
5
6
7
8
9
10
11
double GetLowest(const double array[], int size)
{
	double lowest;

	lowest = array[0];

	for (int count = 1; count < size; count++)
		if (lowest > array[count])
			lowest = array[count];
	return lowest;
}
1
2
for (int count = 1; count < size; count++)
	lowest = array[count];
You forgot to check if array[count] less than lowest
Last edited on
Topic archived. No new replies allowed.