This function is supposed to return the index of the highest temperature. What I have now returns the actual highest temperature so how would I change this to output the index instead?
1 2 3 4 5 6 7 8 9 10 11 12 13
int indexHighTemp(int temperatures[][12])
{
int highIndex;
for (int r=0; r<2; r++)
{
int largest=temperatures[r][0];
for (int c=0; c<12; c++)
if(largest<temperatures[r][c])
largest=temperatures[r][c];
return largest;
}
}
It would look like a normal variable assignment. I can't really give an example without giving away the entire solution.
It's really very simple. You know how to create variables right? And assign them? That's all this is.
1) You already have a variable to keep track of the highest temperature (the variable is "largest"). Create another variable that keeps track of which index had the highest temperature.
2) Set that new variable the same way you set "largest" whenever you find a higher temperature. Only instead of setting it to the temperature, you'd set it to the index.
3) Either print that new variable or return it -- whatever your homework wants (I would think returning it makes more sense, especially given the name of the function.)
EDIT:
Actually, you already have step 1 complete. "highIndex" looks to be what you want.