I'm writing this program to take in the scores from contestants. There are 5 judges, so I'm accumulating the judges scores and sending them to the function to calculate the average. But, once I get to the second contestant, the average is an accumulation of both contestants. How do I get the function to only take each contestant at a time?
do
{
cout<<"Enter the name of the star: ";
cin>>starName;
total = 0;for (int i = 1; i <= 5; i++)
{
cout << "Enter judge "<<i<<" grade: ";
int judgeGrade;
cin >> judgeGrade;
total = total + judgeGrade;
//cout<<total;
if (judgeGrade < 1 || judgeGrade > 10)
{
cout<<"Please enter scores between 1 and 10 for judge "<<i<<": ";
cin>>judgeGrade;
}
}
calcAvgScore(total);
} while (starName != "Done"); // Total contains judges scores after each loop, accumulating the second contestants
Okay, so I have another issue. I haven't learned how to use arrays, but, I need to be able to send the 5 judge scores into a function and have it determine the highest score (another function will find the lowest). I'm at a lost on how to validate the data into finding the highest number. Any suggestions?
Easy way is declare that judges score as global variable, so you don't need to pass it via parameter
Or create static var insde min max function uh.. like this
1 2 3 4 5 6 7 8 9 10 11
int min(int grade){
staticint judge1, judge2, judge3;
if(judge1==0)judge1=grade;elseif(judge2==0)judge2=grade;else
judge3=grade;
if(judge1!=0&&judge2!=0&&judge3!=0){
//find the mininum
judge1=judge2=judge3=0; //clear the variable
//return min to main
}elsereturn 0;
}