There is a bug in one of your functions, but it's not in getLeast()
. Rather than telling you where it is, I'll tell you how you can find it by yourself. Start out in the function that seemingly misbehaves, namely getLeast()
, and check if it actually receives the parameters you expect - inside the loop, use cout
to print array[count]
. Then, you'll see that getLeast()
actually returns the right answer given the parameters it received! Figure out by hand calculation which parameters are wrong (it could be more than one). Which function is responsible for computing that/those parameters? Add some cout
statements to that function so that it prints all the data it looks at, and you'll see that it actually includes too much or too little data in its calculation.
Hint: The error is that one of your loops is unnecessary; you repeat something for several monkeys where you were only supposed to do it for one specific monkey.