### Need help with some if else coding homework

Hey,

This is my first post and I'm having trouble with some c++ homework. Everything works fine until it has to return the average and drop the highest and lowest values. I'm using "if else" for the sorting method and it doesn't seem to be working. Can anybody point me in the right direction of how to fix this?

Requirements:

A particular talent competition 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 highest and lowest score received, then averaging the 3 remaining scores. Write a program that uses these rules to calculate and display 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 5 judges.

- double calcScore() should calculate and return the average of the 3 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 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.

- int findLowest() should find and return the lowest of the 5 scores passed to it
- int findHighest() should find and return the highest of the 5 scores passed to it.

Input Validation: Do not accept judge scores lower than 0 or higher than 10.

Instructors notes:

Make the following change to void getJudgeData().
- The function should take in 2 parameters, not 1 as specified above.
- The first parameter should be a string that holds the values "Judge 1", "Judge 2" and so on.
Each call to the function should contain the judge number.
- The second parameter should follow specifications shown above.

The function prototypes to be used as follows:
void getJudgeData(string j, double &);
double calcScore(double, double, double, double, double);
double findLowest(double, double, double, double, double);
double findHighest(double, double, double, double, double);

CODE:

#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

void getJudgeData(string J, double &);
double calcScore(double, double, double, double, double);
double findLowest(double, double, double, double, double);
double findHighest(double, double, double, double, double);

int main()
{
double Judge1, Judge2, Judge3, Judge4, Judge5;

getJudgeData("1", Judge1);
getJudgeData("2", Judge2);
getJudgeData("3", Judge3);
getJudgeData("4", Judge4);
getJudgeData("5", Judge5);

double averagescore = findHighest(Judge1, Judge2, Judge3, Judge4, Judge5);

cout << "Score 1 Score 2 Score 3 Score 4 Score 5" << endl;
cout << "---------------------------------------------------" << endl;
cout << Judge1 << setw(8) << Judge2 << setw(8) << Judge3;
cout << setw(8) << Judge4 << setw(8) << Judge5 << endl;

cout << "Average=" << averagescore << endl;

return 0;
}

void getJudgeData(string J, double &score)
{
cout << "--- Data Entry for Judge " << J << " -----------" << endl;
cout << "Enter score between 0 and 10: ";
cin >> score;
cout << endl;

while (score < 0 || score > 10)
{
cout << "Score must be in the range 0 - 10. Please re-enter score: ";
cin >> score;
cout << endl;
}
}

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

return average;
}

double findHighest(double score1, double score2, double score3, double score4, double score5)
{
double highest = 0;
if (score1 > highest)
score1 = highest;
if (score2 > score1)
score2 = highest;
else if (score3 > score2)
score3 = highest;
else if (score4 > score3)
score4 = highest;
else if (score5 > score4)
score5 = highest;

return highest;
}

double findLowest(double score1, double score2, double score3, double score4, double score5)
{
double lowest = 10;
if (score1 <= lowest)
score1 = lowest;
else if (score2 < score1)
score2 = lowest;
else if (score3 < score2)
score3 = lowest;
else if (score4 < score3)
score4 = lowest;
else if (score5 < score4)
score5 = lowest;

return lowest;
}
http://www.cplusplus.com/articles/z13hAqkS/

Where do you call your calcScore function?

findHighest could look like this
 ``12345678910111213141516`` ``````double findHighest(double score1, double score2, double score3, double score4, double score5) { double highest = 0; if (score1 > highest) highest = score1; if (score2 > highest) highest = score2; if (score3 > highest) highest = score3; if (score4 > highest) highest = score4; if (score5 > highest) highest = score5; return highest; }``````

findLowest could be done in a similar way
Last edited on
Topic archived. No new replies allowed.