Skip to main content
Tweeted twitter.com/#!/StackCodeReview/status/529229331118030849
deleted 52 characters in body; edited title
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

What is a better approach for findLowest() and findHighest() functions in this simple program?

My code does the job for the most part, but I don't think the two functions that look for the highest and lowest score are the best approach. In theThe instructions tellstell me to use the intint as the return instead of doubledouble, but I can't tell how to take this approach.


A particular talent competition has 5 judges, each of whom awards a score between 0 and 10 to each performer. Fractional scores are allowed. The final score of a performer is determined bt dropping the highest and lowest score recieved, then averaging the 3 remaining scores. Should include the following functions:

  • void getJudgeData() - should ask the user for the judge's score, store it in a reference parameter variable, and validate it. Called in main for each 5 judges

  • double calcScore() - should calculate and return the average of the 3 scores that remain after dropping the highest and lowest scores the prformer recieved. This function can only be called once by main and should be passed the 5 scores.

    Two additional functions should be called by calcScore, which uses the returned info 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.


A particular talent competition has 5 judges, each of whom awards a score between 0 and 10 to each performer. Fractional scores are allowed. The final score of a performer is determined by dropping the highest and lowest score received, then averaging the 3 remaining scores. Should include the following functions:

  • void getJudgeData() - should ask the user for the judge's score, store it in a reference parameter variable, and validate it. Called in main() for each 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 can only be called once by main() and should be passed the 5 scores.

Two additional functions should be called by calcScore(), which uses the returned info 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.

What is a better approach for findLowest() and findHighest() functions in this simple program?

My code does the job for the most part, but I don't think the two functions that look for the highest and lowest score are the best approach. In the instructions tells me to use the int as the return instead of double, but I can't tell how to take this approach.


A particular talent competition has 5 judges, each of whom awards a score between 0 and 10 to each performer. Fractional scores are allowed. The final score of a performer is determined bt dropping the highest and lowest score recieved, then averaging the 3 remaining scores. Should include the following functions:

  • void getJudgeData() - should ask the user for the judge's score, store it in a reference parameter variable, and validate it. Called in main for each 5 judges

  • double calcScore() - should calculate and return the average of the 3 scores that remain after dropping the highest and lowest scores the prformer recieved. This function can only be called once by main and should be passed the 5 scores.

    Two additional functions should be called by calcScore, which uses the returned info 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.


findLowest() and findHighest() functions in this simple program

My code does the job for the most part, but I don't think the two functions that look for the highest and lowest score are the best approach. The instructions tell me to use the int as the return instead of double, but I can't tell how to take this approach.

A particular talent competition has 5 judges, each of whom awards a score between 0 and 10 to each performer. Fractional scores are allowed. The final score of a performer is determined by dropping the highest and lowest score received, then averaging the 3 remaining scores. Should include the following functions:

  • void getJudgeData() - should ask the user for the judge's score, store it in a reference parameter variable, and validate it. Called in main() for each 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 can only be called once by main() and should be passed the 5 scores.

Two additional functions should be called by calcScore(), which uses the returned info 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.

Source Link
RufioLJ
  • 79
  • 1
  • 6

What is a better approach for findLowest() and findHighest() functions in this simple program?

My code does the job for the most part, but I don't think the two functions that look for the highest and lowest score are the best approach. In the instructions tells me to use the int as the return instead of double, but I can't tell how to take this approach.


A particular talent competition has 5 judges, each of whom awards a score between 0 and 10 to each performer. Fractional scores are allowed. The final score of a performer is determined bt dropping the highest and lowest score recieved, then averaging the 3 remaining scores. Should include the following functions:

  • void getJudgeData() - should ask the user for the judge's score, store it in a reference parameter variable, and validate it. Called in main for each 5 judges

  • double calcScore() - should calculate and return the average of the 3 scores that remain after dropping the highest and lowest scores the prformer recieved. This function can only be called once by main and should be passed the 5 scores.

    Two additional functions should be called by calcScore, which uses the returned info 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.


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

// Function prototypes
void getJudgeData(double &someValue);
double calcScore(double a, double b, double c, double d, double e);
double findLowest(double aa, double bb, double cc, double dd, double ee);
double findHighest(double aaa, double bbb, double ccc, double ddd, double eee);

int main ()
{   double scores, avgValue, judge1, judge2, judge3, judge4, judge5;
    
    // Ask for the score of each judge
    getJudgeData(scores);
    judge1 = scores;
    cout << judge1 << endl;
    getJudgeData(scores);
    judge2 = scores;
    cout << judge2 << endl;
    getJudgeData(scores);
    judge3 = scores;
    cout << judge3 << endl;
    getJudgeData(scores);
    judge4 = scores;
    cout << judge4 << endl;
    getJudgeData(scores);
    judge5 = scores;
    cout << judge5 << endl;

    //Outputs the average value
    avgValue = calcScore(judge1, judge2, judge3, judge4, judge5);
    cout << avgValue;

    return 0;
}


/* getJudgeData asks the user for a score between 1 and 10
   gets store in a reference value and validates the input. */
void getJudgeData(double &someValue)
{   cout << "Enter input of your score from 1-10";
    cin >> someValue;
    if (someValue < 1 || someValue > 10) 
    { cout << "Please enter a valid score from 1-10";
      cin >> someValue;
    }
    else {
      someValue;
    }
}

/* calcScore calculates and return the average of 4 scores that remain after
   dropping the highest and lowest scores of the performer revieced. */
double calcScore(double a, double b, double c, double d, double e)
{   double rtValue;
    double lowScore = findLowest(a, b, c, d, e);
    double highScore = findHighest(a, b, c, d, e);

    rtValue = ((a + b + c + d + e) - (lowScore + highScore))  / 3;

    return rtValue;
}

double findLowest (double aa, double bb, double cc, double dd, double ee)
{   
    double lowestScore;

    if ((aa < bb) && (aa < cc) && (aa < dd) && (aa < ee)) {
    lowestScore = aa;
    }
    else if ((bb < aa) && (bb < cc) && (bb < ee) && (bb < ee)) {
    lowestScore = bb;
    }
    else if ((cc < aa) && (cc < bb) && (cc < dd) && (cc < ee)) {
    lowestScore = cc;
    }
    else if ((dd < aa) && (dd < bb) && (dd < cc) && (dd < ee)) {
    lowestScore = dd;
    }
    else if ((ee < aa) && (ee < bb) && (ee < cc) && (ee < dd)) {
    lowestScore = ee;
    }
    return lowestScore;
}

double findHighest (double aaa, double bbb, double ccc, double ddd, double eee)
{   
    double highestScore;

    if ((aaa > bbb) && (aaa > ccc) && (aaa > ddd) && (aaa > eee)) {
    highestScore = aaa;
    }
    else if ((bbb > aaa) && (bbb > ccc) && (bbb > eee) && (bbb > eee)) {
    highestScore = bbb;
    }
    else if ((ccc > aaa) && (ccc > bbb) && (ccc < ddd) && (ccc > eee)) {
    highestScore = ccc;
    }
    else if ((ddd > aaa) && (ddd > bbb) && (ddd > ccc) && (ddd > eee)) {
    highestScore = ddd;
    }
    else if ((eee > aaa) && (eee > bbb) && (eee > ccc) && (eee > ddd)) {
    highestScore = eee;
    }
    return highestScore;
}