Using ultrasonic/ping sensor as function that returns distance in cm as int

Hello all. I am building an Arduino rover and am having a hard time getting the sonar to work. I ended up redoing the code about ten times and then deleting it in rage. I figured it was time to get professional help.

I need help making a function titled "scan" that uses my 4 pin ultrasonic sensor and returns the distance as an integer (Yes, I know I loose accuracy doing that, but I do not need decimals)? I need to know what goes before the setup in the code (what do I need to declare?), and what goes in the actual function at the bottom of the loop.

Thank you for the help

The microsecondsToCentimeters() function in the Ping example from the IDE maybe ?