Tell you're professor he's a fucking idiot. Optimizing your code to make it run more efficiently and succinctly is of paramount importance to programming. What a twat. Looks like you're going to have to go with Wes's original idea:
start the "depth" value at 0.00f.
start a loop up to either |width/2| or |length/2| (whichever is smaller), incrementing by 0.01f each iteration (or however many decimal places you need to be accurate to)
compare the volume at this value of "depth" to the previously acquired volume.
If the volume at this "depth" is smaller than the previous volume, exit the loop and subtract 0.01f from the current "depth" value (so you're effectively backtracking to the maximised volume depth)
return depth.
????
profit.
Pseudocode:
Your professor sounds like an idiot.
start the "depth" value at 0.00f.
start a loop up to either |width/2| or |length/2| (whichever is smaller), incrementing by 0.01f each iteration (or however many decimal places you need to be accurate to)
compare the volume at this value of "depth" to the previously acquired volume.
If the volume at this "depth" is smaller than the previous volume, exit the loop and subtract 0.01f from the current "depth" value (so you're effectively backtracking to the maximised volume depth)
return depth.
????
profit.
Pseudocode:
Code:
declare depth and volumevariable; declare upperboundary; //width/2 or length/2, whichever is smaller for(depth while depth is less than the upper boundary, increasing depth by 0.01 each time) find out volume at this value of depth if this volume < volumevariable then break; otherwise set the volumevariable to the current volume and keep looping subtract 0.01 from the depth to account for breaking out of the loop 1 iteration too late you now have your depth value.