Emotions are the human psychology equivalent of a computer program's main event loop.
Emotions and feelings have causes. A person experiences things in a rough analogy with how programs receive input or internal messages. The emotions then drive behaviour in accordance with what the person has been programmed to do by past experience.
Sometimes -- although not very often, as it is extremely expensive in terms of CPU time -- the rational mind gets involved and has a small amount of input to the course-of-action decision.
Most of the time, the event loop runs efficiently, relying on emotions -- simple heuristics that can process events quickly and reasonably accurately.
The rational mind is only engaged -- at great expense -- when the emotional mind -- that is in the driver's seat and ultimately dictates actions -- decides it is worthwhile to do so.