I am trying to modify this code so that it displays the index of the array element that contains the highest amount.
// searches for the highest amount stored in a one-dimensional array ()
{
//declare array
int dollars [6] = {25, 30, 50, 20, 15, 25} ;
int high = dollars [0]; // assign first element value to high
int x = 1; // begin search with second element
while (x < 6)
{
if (dollars{x} > high) //compare values
high = dollars{x}; // assign element value to high
//end if
x = x+1; // update subscript
} //end while
// display highest value
cout << "High: " << high << endl;
return 0;
} //end of main function



LinkBack URL
About LinkBacks



). 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.