“Just as man cannot survive by any random means, but must discover and practice the principles which his survival requires, so man’s self-interest cannot be determined by blind desires or random whims, but must be discovered and achieved by the guidance of rational principles.” — Ayn Rand
Individuals need a moral code as knowledge for human beings on how to survive, unlike the other animals, is not automatic.
Unlike other organisms — bacteria, elephants or apes which act by instinct — humans beings have no automatic knowledge and must discover the principles needed to survive.
Every human being follows some kind of moral code — whether they are fully conscious of it or not — the choice is whether it is irrational or rational, logically consistent or contradictory, based on life in some imaginary existence or on life on earth. This choice will determine the course of their life and their happiness on earth.
Morality is the “science of self-preservation” and human fulfillment, or in the words of John Galt, a hero in Ayn Rand’s revolutionary novel Atlas Shrugged: “The purpose of morality is to teach you, not to suffer and die, but to enjoy yourself and live.” 
 Ayn Rand, For The New Intellectual 113