Debug error I can't seem to solve + any advice on this program

closed account (i8bjz8AR)
Hi guys, I'm writing a program to score a performers score, based on 5 judges. The score will be calculated by dropping the highest score and the lowest score, then averaging the other 3 together. We aren't allowed to use arrays or vectors yet.. How can i make this program better plus could someone help me with the curly brace error I'm getting...

Here is the original question:

A particular talent competition has five 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 highest and lowest score received, then averaging
the three remaining scores. Write a program that uses this method to calculate a
contestant’s score. It should include the following functions:
• void getJudgeData() should ask the user for a judge’s score, store it in a reference
parameter variable, and validate it. This function should be called by main once for
each of the five 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 just once by main and should be passed the five 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.
• int findLowest() should find and return the lowest of the five scores passed to it.
• int 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.

And here is my code thus 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
68
69
70
71
  #include <iostream>
#include <cstdlib>
using namespace std;

void getJudgeData(double &, int );
void calcScore(double, double, double, double, double);
double findLowest(double, double, double, double, double );
double findHighest(double, double, double, double, double );
double score;
int judge;


int main()

{

double judge1;
double judge2;
double judge3;
double judge4;
double judge5;

getJudgeData(judge1,1);
getJudgeData(judge2,2);
getJudgeData(judge3,3);
getJudgeData(judge4,4);
getJudgeData(judge5,5);

calcScore(judge1, judge2, judge3, judge4, judge5);
system ("pause");
return 0;
}

void getJudgeData(double &score, int x)
{

cout <<"Please enter Judge " << x <<"'s score:\n";
cin >> score;
}

}
while (score < 0 || score > 10)
{
cout << "Score must be between 0 and 10. Please enter a score in that range:\n";
cin >> score;

}
double findLowest(double s1, double s2, double s3, double s4, double s5)
{
double lowest;

return lowest;

}
double findHighest (double s1, double s2, double s3, double s4, double s5)
{
double highest;


return highest;
}

{
void calcScore();
double avgScore
avgScore = (total - highest - lowest) / 3;
cout << "The average score is "<< aveScore << endl;

}

here is for your curly brace error

1
2
3
4
5
6
7
void calcScore ()         // take out the ;
{                               // added the curly brace
double avgScore;        // added the ;

avgScore = (total - highest - lowest ) / 3;
cout << "The average score is " << aveScore << endl;
}
Last edited on
closed account (i8bjz8AR)
okay, now I'm getting a curly brace error on line 41!
Last edited on
A little bit of formatting will go a long way to identifying errors:
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
#include <iostream>
#include <cstdlib>
using namespace std;

void getJudgeData(double &, int);
void calcScore(double, double, double, double, double);
double findLowest(double, double, double, double, double);
double findHighest(double, double, double, double, double);
double score;
int judge;

int main() {
  double judge1;
  double judge2;
  double judge3;
  double judge4;
  double judge5;

  getJudgeData(judge1, 1);
  getJudgeData(judge2, 2);
  getJudgeData(judge3, 3);
  getJudgeData(judge4, 4);
  getJudgeData(judge5, 5);

  calcScore(judge1, judge2, judge3, judge4, judge5);
  system("pause");
  return 0;
}

/**
 * Avoid using cin >> as it's very error prone
 */
void getJudgeData(double &score, int x) {
  cout << "Please enter Judge " << x << "'s score:\n";
  cin >> score;
}

/**
 * Where does this code belong? It's not in any method
 */
}
while (score < 0 || score > 10)
{
  cout << "Score must be between 0 and 10. Please enter a score in that range:\n";
  cin >> score;

}

/**
 * This method does nothing
 */
double findLowest(double s1, double s2, double s3, double s4, double s5) {
  double lowest;
  return lowest;
}

/**
 * Also does nothing
 */
double findHighest(double s1, double s2, double s3, double s4, double s5) {
  double highest;
  return highest;
}

/**
 * More code that is not inside any method??
 */
{
  void calcScore();
  double avgScore
  avgScore = (total - highest - lowest) / 3;
  cout << "The average score is "<< aveScore << endl;
}
try something like this to find lowest and highest.

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
double findLowest(double s1, double s2, double s3, double s4, double s5) 
{
 

double lowest = s1;

	if (s2 < lowest)
	{
		lowest = s2;
	}
	if (s3 < lowest)
	{
		lowest = s3;
	}

	if (s4 < lowest)
	{	
		lowest = s4;
	}

	if (s5 < lowest)
	{
		lowest = s5;
	
	}
	return lowest;
}
closed account (i8bjz8AR)
I tried that and it gave many more errors, wasn't my method before better? I also moved and edited my curly braces and I can't get it running.. :(
Last edited on
Look at the comments in your code that I put. I've highlighted all of the errors.

As for getting the minimum use built in functions:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
double get_min(double a, double b, double c, double d) {
  return min(a, min(b, min(c, d)));
}

/**
 * Main method
 */
int main() {
  double a = 1.0;
  double b = 2.5;
  double c = 0.9;
  double d = 3.0;

  cout << "Min is: " << get_min(a, b, c, d) << endl;
  return 0;
}

closed account (i8bjz8AR)
Thanks for all the help! I've changed up the two methods you highlighted, and the parts where you say this isn't in any method, i tried removing and adding curly braces in different places... This is what i have at the moment

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

void getJudgeData(double &, int);
void calcScore(double, double, double, double, double);
double findLowest(double, double, double, double, double);
double findHighest(double, double, double, double, double);
double score;
int judge;

int main() {
  double judge1;
  double judge2;
  double judge3;
  double judge4;
  double judge5;

  getJudgeData(judge1, 1);
  getJudgeData(judge2, 2);
  getJudgeData(judge3, 3);
  getJudgeData(judge4, 4);
  getJudgeData(judge5, 5);

  calcScore(judge1, judge2, judge3, judge4, judge5);
  system("pause");
  return 0;
}


void getJudgeData(double &score, int x) {
  cout << "Please enter Judge " << x << "'s score:\n";
  cin >> score;
}


while (score < 0 || score > 10)
{
  cout << "Score must be between 0 and 10. Please enter a score in that range:\n";
  cin >> score;

}


double findHighest() {

	double score, score1, score2, score3, score4;
	double highest = 0;

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

	return highest;

}

double findLowest() {

	double score, score1, score2, score3, score4;
	double lowest = 10;

	if (score < lowest)
		lowest = score;
	else if (score1 < score)
		lowest = score1;
	else if (score2 < score)
		lowest = score2;
	else if (score3 < score)
		lowest = score3;
	else if (score4 < score)
		lowest = score4;

	return lowest;
}

  void calcScore();
  double avgScore
  avgScore = (total - highest - lowest) / 3;{
  cout << "The average score is "<< aveScore << endl;
}
See comments:
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
#include <iostream>
#include <cstdlib>
using namespace std;

void getJudgeData(double &, int);
void calcScore(double, double, double, double, double);
double findLowest(double, double, double, double, double); 
double findHighest(double, double, double, double, double);
double score;
int judge;

int main() {
  double judge1;
  double judge2;
  double judge3;
  double judge4;
  double judge5;

  getJudgeData(judge1, 1);
  getJudgeData(judge2, 2);
  getJudgeData(judge3, 3);
  getJudgeData(judge4, 4);
  getJudgeData(judge5, 5);

  calcScore(judge1, judge2, judge3, judge4, judge5);
  system("pause");
  return 0;
}


void getJudgeData(double &score, int x) {
  cout << "Please enter Judge " << x << "'s score:\n";
  cin >> score;
}


/**
 * This code is still not in any function. It's just
 * sitting in the middle of nowhere
 */
while (score < 0 || score > 10)
{
  cout << "Score must be between 0 and 10. Please enter a score in that range:\n";
  cin >> score;

}


/**
 * You broke this by removing all of the parameters it needs to work
 */
double findHighest() {

  double score, score1, score2, score3, score4;
  double highest = 0;

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

  return highest;

}

/**
 * You broke this by removing all of the parameters it needs to work
 */
double findLowest() {

  double score, score1, score2, score3, score4;
  double lowest = 10;

  if (score < lowest)
    lowest = score;
  else if (score1 < score)
    lowest = score1;
  else if (score2 < score)
    lowest = score2;
  else if (score3 < score)
    lowest = score3;
  else if (score4 < score)
    lowest = score4;

  return lowest;
}


/**
 * This code is still not in any function. It's just
 * sitting in the middle of nowhere
 */
  void calcScore();
  double avgScore
  avgScore = (total - highest - lowest) / 3;{
  cout << "The average score is "<< aveScore << endl;
}
closed account (i8bjz8AR)
I guess I'm just confused on how to fix this. Should void calcScore go before my while loop of score? Just got into functions with parameters in class and have no experience with them.. Thanks!
1
2
3
4
5
6
while (score < 0 || score > 10)
{
  cout << "Score must be between 0 and 10. Please enter a score in that range:\n";
  cin >> score;

}

Belongs in your getJudgeData function



1
2
3
4
5
  void calcScore();
  double avgScore
  avgScore = (total - highest - lowest) / 3;{
  cout << "The average score is "<< aveScore << endl;
}

should be:
1
2
3
4
5
void calcScore() {
  double avgScore
  avgScore = (total - highest - lowest) / 3;
  cout << "The average score is "<< aveScore << endl;
}
Last edited on
closed account (i8bjz8AR)
okay, i changed the calcScore and pasted that, and i see what i did wrong there. now the getJudgeData, this is what I have now
1
2
3
4
5
6
7
8
void getJudgeData(double &score, int x)

while (score < 0 || score > 10)
{
  cout << "Score must be between 0 and 10. Please enter a score in that range:\n";
  cout << "Please enter Judge " << x << "'s score:\n";
  cin >> score;
}
, i'm getting an expected initializer error before while on line 33, and avgScore is not declared + says it needs an initializer as well, what do i need to add here?
Topic archived. No new replies allowed.