Originally posted by Unregistered
I'm not quite sure about this but it looks like the code above would give you 5 for a value of x every time.
You're right. I didn't even catch that. I normally use a break-point test in my loops ( though I didn't include one here ). I didn't load the index value into high due to the fact that ( as I understood it ) he needs to return the value and the index.
What I should have put was:
Code:
int i, x=1, high=dollar[0];
while(x<6)
{
if(dollar[x]>high)
{
i=x;
high=dollar[x];
}
x++;
}
cout<<"High value: "<<high<<" found at index: "<<i<<endl;
Thanks for catching that!