### 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:

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071`` `````` #include #include 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

 ``1234567`` ``````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:
 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273`` ``````#include #include 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.

 ``123456789101112131415161718192021222324252627`` ``````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:
 ``12345678910111213141516`` ``````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

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889`` ``````#include #include 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; } ``````
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103`` ``````#include #include 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!
 ``123456`` ``````while (score < 0 || score > 10) { cout << "Score must be between 0 and 10. Please enter a score in that range:\n"; cin >> score; }``````

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

should be:
 ``12345`` ``````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
 ``12345678`` ``````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.