I'm writing a code that asks the user for 5 judges scores, and then takes away the highest score and the lowest score, and averages the 3 middle scores and displays that as the contestants score. I'm getting errors that my "local function definitions are illegal" for all my different functions. And that "answer", "lowest", and "highest" and undeclared identifiers. At first I had all of these in the beginning of the main, but then I moved "lowest" and "highest" to the function that they were being used in and left "answer" in the beginning of the main. Is that where all these should be?
Code:
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
void getJudgeData (double &);
void calcScore (double, double, double, double, double);
double findLowest (double, double, double, double, double);
double findHighest( double, double, double, double, double);
int main ()
{
do
{
double score1, score2, score3, score4, score5;
char answer = 'y';
cout << "Welcome to Star Search" << endl << "----------------------";
void getJudgeData (double &score)
{
int counter = 1;
while (counter <= 5)
{
cout << "Enter score between 0 and 10 ";
cin >> score;
if ((score < 0) || (score > 10))
{
cout << "Score must be in the range of 0-10. Please re-enter score. ";
cin >> score;
}
counter++;
}
}
findLowest (score1, score2, score3, score4, score5);
findHighest (score1, score2, score3, score4, score5);
calcScore (score1, score2, score3, score4, score5);
double findLowest (double s1, double s2, double s3, double s4, double s5)
{
double lowest;
if ((s1 < s2) && (s1 < s3) && (s1 < s4) && (s1 < s5))
{
lowest = s1;
}
else if ((s2 < s1) && (s2 < s3) && (s2 < s4) && (s2 < s5))
{
lowest = s2;
}
else if ((s3 < s1) && (s3 < s2) && (s2 < s4) && (s2 < s5))
{
lowest = s3;
}
else if ((s4 < s1) && (s4 < s2) && (s4 < s3) && (s2 < s5))
{
lowest = s4;
}
else if ((s5 < s1) && (s5 < s2) && (s5 < s3) && (s5 < s4))
{
lowest = s5;
}
}
double findHighest (double s1, double s2, double s3, double s4, double s5)
{
double highest;
if ((s1 > s2) && (s1 > s3) && (s1 > s4) && (s1 > s5))
{
highest = s1;
}
else if ((s2 > s1) && (s2 > s3) && (s2 > s4) && (s2 > s5))
{
highest = s2;
}
else if ((s3 > s1) && (s3 > s2) && (s2 > s4) && (s2 > s5))
{
highest = s3;
}
else if ((s4 > s1) && (s4 > s2) && (s4 > s3) && (s2 > s5))
{
highest = s4;
}
else if ((s5 > s1) && (s5 > s2) && (s5 > s3) && (s5 > s4))
{
highest = s5;
}
}
void calcScore (double s1, double s2, double s3, double s4, double s5)
{
double middle;
double finalScore;
middle = s1 + s2 + s3 + s4 + s5 - lowest - highest;
finalScore = middle/3.0;
cout << "Low score is " << lowest << endl;
cout << "High score is " << highest << endl;
cout << "The contestants talent score is " << finalScore << endl;
}
cout << "Do you want to try again? (y/n) ";
cin >> answer;
}
while ((answer = 'y') || (answer = 'Y'));
}