problem with distance sensor project with HC-SR04 sensor

hi guys I’m new with arduino still dont know much about it. i have project about making a distance sensor with ultrasonic HC-SR04 sensor. my aim is the sensor not only give me the distance but the echo pin will send a signal to input digital of arduino and control how buzzer works.
i already made 4 conditions. first is when the distance of the object more than equal 300 then the buzzer will not ringing and 'out of range' text will appear in serial monitor. if the distance between 200 and 300 buzzer will ringing with 500 microseconds delay of buzzer in 'HIGH' condition and printed to serial monitor to. the other 2 conditions are the distance below the last one , and i decrease the delay( to make the buzzer ringing faster).
. the problem is the sensor is not stable when i put more than two conditions. when the distance more than 300 it should be printed 'out of range' but it's not ,it is fluctuated like this (out of range , 90,out of range,89,out of range,96). so is there any mistake on my coding ? if you guys think that what i write is not clear enough please kindly see the screen shoot. thank you very much, i appreciate every opinion or solution from you guys.

Can you please post code instead of using screenshots (that chew away my bandwidth ;)). It's a lot to copy and paste than to type everything again.

Please post code using code tags. [code] your code here [/code] will result in

 your code here

My short experience with the HC-SR04 is that readings always fluctuate a bit. So you need to allow for a bit play.

distance > 100 cm
distance > 50 cm and distance < 95 cm
distance < 45 cm

You might need a slightly different approach in your code but I will not 'read' pictures :wink: so can't tell.