Erm, flowcharts are supposed to be your foundation for the logic of the code. It is not the other way around.
Trying to debug the code to construct a flowchart is wrong. It's the other way around it's supposed to be.
It isn't particularly hard since it's such a small topic, so any thousand information sites on the web should be able to provide the entire theory.