0
votes

I have an program that is suppose to have the user input 5 scores then the program will find the highest and lowest numbers that were entered and eliminate them, then find the avg of the remaining numbers.

The program was not calculating the correct avg if score two was the lowest so I put a few out statements in my findLowest function and found that it was not recording the scores properly. a busy cat

I not sure why it eliminates the first score all the time. Would it better to just ask for each score individually since there are only five scores

int main()
{
    string judges[] = {"Judge 1","Judge 2","Judge 3","Judge 4","Judge 5"};
    int score[] = {0,0,0,0,0,0};

    for ( int i=0; i<5 ;i++ )
    {
        score[i] = getJudgeData(judges[i]);
    }
    calcAverage(score[1],score[2],score[3],score[4],score[5]);

return 0;
}

For the function that gets the score from the user: int getJudgeData(string judge) { int input = -1;

    while( input < 0 || input > 10 )
    {
    cout << "Enter the score from " << judge <<endl;
    cin >> input;
    }

    return input;
}
1

1 Answers

2
votes
calcAverage(score[1],score[2],score[3],score[4],score[5]);

This is wrong syntactically and logically. Syntactically as you are trying to access array out of its bound which is undefined behavior . Logically as you are not considering initial value ( arr[0] ).

This rather should be:-

calcAverage(score[0],score[1],score[2],score[3],score[4]);