A pathfinding solution

Also look at dist() which is the same like the formula above

So for loop over the lakes and store the number of the lake with the smallest distance to the herbivores.

float distMy = dist( herbiv.x, herbiv.y,
lake1X, lake1Y);