How to design a comparator using op-amp?
You are assuming the op-amp will output 5V when high and 0V when low, they do not.

Look at the green output in your image, notice high is under 4.5V and low is above ground.

You would need to use those voltages in your math. 



Also be aware, Voh and Vol of the op-amp will vary from device to device, with temperature, and depending on what load is attached to the output. Using op-amps as comparators is generally not a great idea.

ADDITION:

The above is partly the reason why most actual comparator devices are open collector outputs.







simulate this circuit &ndash; Schematic created using CircuitLab

\$Th_{lo} \approx  V_{cc} * R2||R3/(R1 + R2||R3)\$

\$Th_{hi} = V_{cc} * R2/(R2 + R1||(R3+R4))\$