I'm trying to build a program that takes scores from judges, drops the highest and lowest and averages the remaining three scores. Problem is, the program compiles but I keep getting zero as an average. What am I doing wrong???
uh I don't? So I have to put avgOut within the scope of the calcScore function? I think my main problem is I'm having problems understanding how reference variables work.
Thanks for the responses. This is what I have now and I'm still getting 0.00 as an average. (I didn't change anything in main.)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
int main ()
{
double avgOut=0;
cout << fixed << showpoint << setprecision(2);
cout << "-----------------------------------Star Search---------------------------------\n\n";
cout << "Enter 5 scores for the contestant and I will drop the lowest and highest to find the average score."<<endl;
getJudgesData (judge1);
getJudgesData (judge2);
getJudgesData (judge3);
getJudgesData (judge4);
getJudgesData (judge5);
cout<<"Average Score: ";
calcScore(judge1, judge2, judge3, judge4, judge5, avgOut);
cout<< avgOut;
Does score stop existing when the function returns so the values stored are deleted? (Btw and I should have said this earlier but I must use void functions for getJudgesData and calcScore.)
ETA - I got it, yes! Thanks again. Your explanation really helped me understand the problem better.
Does score stop existing when the function returns so the values stored are deleted?
Yes, score is deleted when you exit getJudgesData().
cire's point and the reason he underlined the judgesScore argument is that you're passing it by reference so that it will be modified in the caller, but you never reference it.
Yes, score is deleted when you exit getJudgesData().
cire's point and the reason he underlined the judgesScore argument is that you're passing it by reference so that it will be modified in the caller, but you never reference it.
Thank you! These explanations have made it crystal clear now.