uninitializing problem

I keep having initializing errors in the findlowest and findhighest functions, help?
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/***********************************************************************************************************
A particular talent composition has 5 judges, each of whom awards a score between 0 and 10 to each performer. 
Fractional scores, such as 8.3, are allowed. A performer's final score is determined by dropping the lowest 
and the highest score received, then averaging the 3 remaining scores. Write a program that uses this method 
to calculate a contestant's score. It should include the following functions:

double getJudgeData() should ask the user for a judge's score and validate the score. This function 
should be called 5 times from main, once for each of the 5 judges.
void calcScore() should calculate and display the average of the three scores that remain after 
dropping the highest and lowest scores the performer received. This function should be called once 
from main, and should be passed the 5 scores.
The last two functions, described below, should be called by calcScore, which uses the returned 
information to determine which of the scores to drop.

double findLowest() should find and return the lowest of the five scores passed to it.
double findHighest() should find and return the highest of the five scores passed to it.
Input validation: Do not accept judge scores lower than 0 or higher than 10.
*************************************************************************************************************/
#include <iostream>

using namespace std;

double getJudgeData1(double score1) {

	cout << "Judge 1 please enter your score: ";
	cin >> score1;

	while (score1 < 0.0 || score1 > 10.0) {
		cout << "The score entered must be between 0 and 10. Please enter again." << endl;
		cout << "\nJudge 1 please enter your score: ";
		cin >> score1;
	}
	return score1;
}

double getJudgeData2(double score2) {

	cout << "Judge 2 please enter your score: ";
	cin >> score2;

	while (score2 < 0.0 || score2 > 10.0) {
		cout << "The score entered must be between 0 and 10. Please enter again." << endl;
		cout << "\nJudge 2 please enter your score: ";
		cin >> score2;
	}
	return score2;
}

double getJudgeData3(double score3) {

	cout << "Judge 3 please enter your score: ";
	cin >> score3;

	while (score3 < 0.0 || score3 > 10.0) {
		cout << "The score entered must be between 0 and 10. Please enter again." << endl;
		cout << "\nJudge 3 please enter your score: ";
		cin >> score3;
	}
	return score3;
}

double getJudgeData4(double score4) {

	cout << "Judge 4 please enter your score: ";
	cin >> score4;

	while (score4 < 0.0 || score4 > 10.0) {
		cout << "The score entered must be between 0 and 10. Please enter again." << endl;
		cout << "\nJudge 4 please enter your score: ";
		cin >> score4;
	}
	return score4;
}

double getJudgeData5(double score5) {

	cout << "Judge 5 please enter your score: ";
	cin >> score5;

	while (score5 < 0.0 || score5 > 10.0) {
		cout << "The score entered must be between 0 and 10. Please enter again." << endl;
		cout << "\nJudge 5 please enter your score: ";
		cin >> score5;
	}
	return score5;
}

double findHighest(double score1, double score2, double score3, double score4, double score5) {

	//double score1, score2, score3, score4, score5;
	//double highest = 0;

	if (score1 > highest)
		highest = score1;
	//else if (score1 > score1)
	//	highest = score1;
	else if (score2 > score1)
		highest = score2;
	else if (score3 > score1)
		highest = score3;
	else if (score4 > score1)
		highest = score4;
	else if (score5 > score1)
		highest = score5;

	return highest;

}

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

	//double score1, score2, score3, score4, score5;
	//double lowest = 10;

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

void calcScore() {

	double score1, score2, score3, score4, score5;
	double lowest;
	double highest;
	
	double findHighest(highest);
	double findLowest(lowest);
	
	double totalScore = score1 + score2 + score3 + score4 + score5; 
	double avgScore = (totalScore - highest - lowest)/3;
	
	cout << "\nThe contestant's average score is: " << avgScore << endl;
}

int main() {

	double score5, score1, score2, score3, score4;
	double lowest, highest;

	getJudgeData1(score1);
	getJudgeData2(score2);
	getJudgeData3(score3);
	getJudgeData4(score4);
	getJudgeData5(score5);

	calcScore();

	return 0;
}
Line 93: highest is undefined. Why is line 91 commented out?

Line 115: lowest is undefined. Why is line 113 commented out?

Line 136-137: Are these function delcarations or function calls? You can't embed a function declaration inside another function. If these are function calls, the double should be removed.

Line 139: Trying to calculate totalScore from uninitialized variables.

Lines 150-154: You're passing score1-score5 by value and ignoring the return result. score1-score5 are NOT updated.

Last edited on
I commented them out in an attempt and forgot to return them.

136-137 are meant to call lowest and highest for the calculations

In main i thought that by having them called they can store the data can then be sent to the other functions
136-137 are meant to call lowest and highest for the calculations

Don't put a type in front of a function call.

In main i thought that by having them called they can store the data can then be sent to the other functions

Only if you pass by reference. You're passing by value, there the called routines get a copy of the argument.
so if i put & it should pass by reference
Topic archived. No new replies allowed.