Problems with displaying different sensor values on lcd with ir sensor.

Did you make ANY attempt to create the three functions I mentioned? Did you make ANY attempt to move any of your code into those functions?

If not, why not? You will never learn if you never try.