// I need to change this to arrays but can not figure it out
#include <iostream>
using namespace std;
// Function Prototypes
void getJudgeData(double &);
double calcScore(double, double, double, double, double);
int findHighest(double, double, double, double, double);
int findLowest(double, double, double, double, double);
int main()
{
double Score1, Score2, Score3, Score4, Score5;
// Display introduction
cout << "\nThis program calculates a performer’s final score.\n"
<< "---------------------------------------------------\n\n";
// Call function getJudgeData once for each judge
getJudgeData(Score1);
getJudgeData(Score2);
getJudgeData(Score3);
getJudgeData(Score4);
getJudgeData(Score5);
cout << "\nThe contestant’s score is ";
// Call function calcScore passing to it the five scores
cout << calcScore(Score1, Score2, Score3, Score4, Score5);
cout << endl;
return 0;
}
void getJudgeData(double &Score)
{
do
{
cout << "Enter a judge’s score: ";
cin >> Score;
if (Score < 0 || Score > 10)
{
cout << "\nError! Invalid score.\n"
<< "Judge's score must be greater than 0 and less than 10.\n";
}
// Call function findHighest and findLowest passing 5 scores to them
High = findHighest(Score1, Score2, Score3, Score4, Score5);
Low = findLowest(Score1, Score2, Score3, Score4, Score5);
^ and the functions would look like this: int foo(double Score1, double Score2, double Score3, double Score4, double Score5)
becomes int foo(double Scores[])
call like: foo(Scores);
If you want to save lines of code, you can use a for loop to iterate
1 2 3 4
for (int i = 0; i < 5; i++)
{
Scores[i] = /* ... */;
}
all the stuff you replaced with arrays needs to change.
for example (pick any random line really)
else if (Score4 < Score2 && Score4 < Score3 && Score4 < Score1 &&
would be
else if (Score[3] < Score[1] && Score[3] < Score[2] && Score[3] < Score[0] &&
it may be in your best interest due to your existing code to allocate an extra slot in Score and keep the old names consistent. if you did that you could just put [] around your variable name number part (eg score3 becomes score[3] instead of score[2]) and make it much easier to edit the code. I recommend, whichever way you do it, to carefully do search and replaces... eg replace all Score[3] with Score[2] (or 3 if you add the extra space) and let the text editor do this work for you.
the same will be true for any other variables you changed.
then you can try to compile it and chase down the errors and fix them, which should just be your function calls.
and, for more than a couple lines of code, use code tags (<> on the side bar) for code so we can read it easier. Im used to hacking in a plain text editor, most folks here are used to syntax highlighting and indents and stuff.