Need Help with Piezo Buzzer and Ultrasonic Sensor code

Did you move those lines out of the loop().
Are the distances printed to the serial monitor?