Look at the skeleton code above (the code you were given).
1 2 3 4 5 6 7 8
|
double maxSales(double total[],int& maxValIndex, int size)
{
// write code and place here to correctly determine
// the max total value
// and the index where it occurs
return maxVal;
}
|
Two things to notice here. Look at the comment. It says you are to return two things, a
value and the corresponding
index.
It does that by using
maxVal for the value, and reference parameter
maxValIndex for the index.
Now refer to the code posted at the top of this thread.
1 2 3 4 5 6 7 8 9
|
double maxSales(double total[],int& maxValIndex, int size)
{
for(int i=1;i<size;i++)
{
if (total[i] > total[maxValIndex])
maxValIndex=i;
}
return maxValIndex;
}
|
What I see here is the function returns two items, but instead of the required
value and its
index, actually the index value is returned in both cases.
Also I see that this line:
return maxVal;
has been replaced by
return maxValIndex;
.
Look at the return type of the function:
double maxSales()
It is supposed to return a type
double. (maxValIndex is an integer).
As I suggested earlier, I believe you need to define the variable
maxVal (as supplied, your professor's code does not compile successfully).
So, you need something like this:
1 2 3
|
double maxVal;
maxval = /* here add the appropriate code */
return maxVal;
|
Actually, the above three lines of code could probably be simplified and done in just one line. But I wrote it that way for the purposes of explanation.
I hope this gets you a step closer to the solution.