Distance to problem?

Should I reset the distance variable each time, this seems a bit silly as I don’t understand what could be changing it or even corrupting it?

For the first room it’s only the 5th attemot that’s out of whack.

However for the second room, which follows a similar structure bp it’s worse as the 3rd and 5th attempt provides a wrong reading.

I’m going out of my mind trying to figure it out