lost with this assignment

I have to write a program that will take the score of 5 judges and then drop the highest and lowest and then out put the average of the remaining three. This is what I have so far, but the average keeps showing as 0.


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
#include <iostream>
using namespace std;
void getJudgeData();
double calcScore();
double findLowest();
double findHighest();
double calcScore(double score1, double score2, double score3, double score4, double score5);

int main()

{

getJudgeData();
	return 0;
}

void getJudgeData()
{
	double score1, score2, score3, score4, score5;
	double average = 0;
	double total = 0;
	double lowest = 0;
	double highest = 0;
	double calcScore(double, double, double, double, double, double, double, double, double);
	cout <<"Judge 1 Score: ";
	cin >> score1;
	if ( score1 < 0 || score1 > 10)
{
	cout <<"Re-Enter Score: ";
	cin >> score1;
}
	cout <<"Judge 2 Score: ";
	cin >> score2;
	if ( score2 < 0 || score2 > 10)
{
	cout <<"Re-Enter Score: ";
	cin >> score2;
}
	cout <<"Judge 3 Score: ";
	cin >> score3;
	if ( score3 < 0 || score3 > 10)
{
	cout <<"Re-Enter Score: ";
	cin >> score3;
}
	cout <<"Judge 4 Score: ";
	cin >> score4;
	if ( score4 < 0 || score4 > 10)
{
	cout <<"Re-Enter Score: ";
	cin >> score4;
}
	cout <<"Judge 5 Score: ";
	cin >> score5;
	if ( score5 < 0 || score5 > 10)
{
	cout <<"Re-Enter Score: ";
	cin >> score5;
}
 cout << "The average score is " << average << endl;
}

double calcScore(double average, double total, double highest, double lowest, double score1, double score2, double score3, double score4, double score5)

{
	double findLowest(double, double, double, double, double);
	double findHighest(double, double, double, double, double);
	total = score1 + score2 + score3 + score4 + score5;
	average = (total - highest - lowest) /3;
	return average;
}

double findLowest( double lowest, double score1, double score2, double score3, double score4, double score5)

{
	lowest = score1;
	if (score2 < score1)
{
	lowest = score2;
}
	if (score3 < score1)
{
	lowest = score3;
}
	if (score4 < score1)
{
	lowest = score4;
}
	if (score5 < score1)
{
	lowest = score5;
}
	return lowest;
}

double findHighest(double highest, double score1, double score2, double score3, double score4, double score5)
{
	highest = score1;
	if (score2 > score1)
{
	highest = score2;
}
	if (score3 > score1)
{
	highest = score3;
}
	if (score4 > score1)
{
	highest = score4;
}
	if (score5 > score1)
{
	highest = score5;
}
	return highest;
}
Last edited on
>Firstly, in findHighest(), replace the "score1" in your if statements with "highest". This will ensure that you're always checking against the highest value, not just score1.

>Do the same in findLowest(), except with "lowest".

>In calcScore(), you are calling the methods findHighest() and findLowest() however, you are not storing their return values. Remember that "highest" and "lowest" are local to findHighest() and findLowest() respectively. In other words, try something like the following in your calcScore() function.

1
2
  double highest_score = findHighest(...);
    //etc... 


>Make all of your variables in calcScore() pass by reference. This will allow you to modify the original values of the variables rather than just copies of them.

ex)
double calcScore(double& average, double& total, double& highest, double& lowest, double& score1, double& score2, double& score3, double& score4, double& score5)

IMPORTANT: Before you do this, initialize all of your score variables.


>In getJudgeData(), replace your if statements with while loops in order to continue asking for ints even after the first and second fail (keep the same loop condition).
Last edited on
1
2
	double findLowest(double, double, double, double, double);
	double findHighest(double, double, double, double, double);

This code isn't actually doing anything. You need to pass the values through to these methods.
Last edited on
I still can't seem to figure out how this should be done.
You supply the names of the variables to the function.
double result = findLowest(a,b,c,d,e)

Your functions take one more parameter than they need if you plan on returning the result.
Topic archived. No new replies allowed.