I was wondering, during a time of war did Rome elect a monarch instead of having a Republic? Also why did they choose such a system?
FYI Batman reminded me of this, although I don't recall the details. - https://youtu.be/UfcemNhlqyA?t=73
The short answer is no: during times of war, the Romans did not institute a monarchy instead of a Republic. What you're referring to is the office of dictator (which should not be confused with modern dictatorships): an official with sole power, who was nonetheless a part of the Republic.
The Roman constitution is traditionally understood to have been formed after the expulsion of the kings, the last of which had been proud and cruel. Throughout the generations, the Romans abhorred everything that reeked of regal government: the authority of the kings was divided between two annually elected consuls, and even religious duties that required the participation of a king were transferred to a minor official with the honorary title of "king of sacrifices."
Despite all this, in times of war the Romans realized that authority sometimes, for practical reasons, had to be committed to a single magistrate. Thus, in times of grave emergency, they elected a dictator, who assumed sole control for a period of six months.
Perhaps the most famous occasion of this is Cincinnatus (see Livy Book 3), who, when Rome was threatened by an invasion of the Samnites, was elected dictator to deal with the crisis; he was found at work on his farm when he was told of the election, assumed power, defeated the Samnites, and then gave up his power and returned to his farm -- in 16 days.
The other famous example is Fabius Maximus (see Livy 22 and Plutarch's Life of Fabius). During Hannibal's invasion of Italy, after Hannibal had destroyed multiple Roman armies and Rome was threatened, says Plutarch:
But all were brought at last to be of one mind, namely, that the situation demanded a sole and absolute authority, which they call a dictatorship, and a man who would wield this authority with energy and without fear; that Fabius Maximus, and he alone, was such a man, having a spirit and a dignity of hand that fully matched the greatness of the office, and being moreover at the time of life when bodily vigour still suffices to carry out the counsels of the mind, and courage is tempered with prudence. Accordingly, this course was adopted, and Fabius was appointed dictator.
This Fabius followed a policy of following and harassing Hannibal, but never directly engaging him in a pitched battle (which Hannibal would win), and so he was given the partly joking honorific Cunctator, "delayer." A famous line of Ennius says that he saved the Republic by delaying (cunctando restituit rem). He was regularly reelected to the position over the course of the war, but always for a fixed six-month term.
Later, the office of dictator fell into disuse, and when it was resurrected by Sulla and Caesar in the civil wars of the 1st century BC, it was little more than a way to cloak their power under forms of law. But traditionally, the office was perfectly legal and constitutional, and part of the Republic.