error: 'ping' was not declared in this scope

I don't know if it is better to place the movements (forward, back, right, left, stop) in functions or code them all in the void Loop() using 'if' and 'if else' statements. Which is better?

You'll need the if/else if/else statements to determine which function to call. Whether they go in loop() or a function called move() is up to you. The code that actually causes the robot to move forward, backward, etc. should go in a function that gets called.

That way, you can verify that goForward(), goBackward(), goLeft(), and goRight() do exactly what they are supposed to, independent of the decisions to call a function.

Once it detects it is within the correct distance from the target, it should shut down.

Stopping and shutting down are two completely different things. Which one do you really want th have happen?