That's my point, more light will result in a lower voltage. So the "total" variable will always be less than or equal to "ambient", but the result is "total - ambient".
Edit: Also, I don't know the processor speed used in that example, but LEDs aren't instantaneously on or off. They have a rise and fall time. I would wait 5-10uS between setting the LED and reading the sensor. And the LED should probably be turned off at the end of the routine instead of leaving it on...save on batteries.