In this program, we will implement a "ranked-choice" election system. Here's how they work, according to Time Magazine (https://time.com/5718941/ranked-choice-voting/):

"Ranked-choice voting is an electoral system that allows people to vote for multiple candidates, in order of preference. Instead of just choosing who you want to win, you fill out the ballot saying who is your first choice, second choice, or third choice (or more as needed) for each position.

The candidate with the majority (more than 50%) of first-choice votes wins outright. If no candidate gets a majority of first-choice votes, then it triggers a new counting process. The candidate who did the worst is eliminated, and that candidate's voters ballots are redistributed to their second-choice pick. In other words, if you ranked a losing candidate as your first choice, and the candidate is eliminated, then your vote still counts: it just moves to your second-choice candidate. That process continues until there is a candidate who has the majority of votes."

Input file: In our program, an election result is stored in an input file called "ElectionResults.txt".

The file starts with two integers. The first integer is how many voters participated in the election and the second is how many candidates were in the election.

The rest of the input file is a list of voters' data for the election.

Each voter's data is on one line and starts with the voters ten-digit ID number (store this as a string, because it may start with zeros).

After the ID number is a list of the voter's choices from first choice to last choice.

The candidates are assumed to be numbered from 1 to the number of candidates so if there are three candidates, they will simply be called 1, 2, and 3.

Example input file: see image.

Example execution: The next page shows an example running of the program. The output is to the screen. Your output should look the same.

At first it shows the total votes for each candidate using only the first choices of every voter.

Until one candidate has more than 50% of the vote, the candidate with the fewest votes is eliminated and all of the voters that voted for that candidate use their next available choice.

After a candidate is eliminated, the votes are recalculated using only the remaining candidates.

Detail #1: Once a candidate is removed, they cannot be put back into the election. None of their votes are counted for the rest of the election counting. Any candidate that has 0 votes in the first count must be eliminated if the election is not won in the first count.

Detail #2: If two or more candidates tie for lowest number of votes, eliminate only one of them, it doesn't matter which one you eliminate. I know this is not fair but making this situation fair is not easy and we wont worry about it in this program. None of these elections are real.

Detail #3: You are not allowed to use vectors or any other data structure other than arrays unless you program them yourself or get them from class example code.

Detail #4: Your program does not know how many voters or candidates are in the election. Your program can assume both numbers are positive, but the program must handle any valid values for those data points.

Detail #5: Your program must work for any input file that has the format described above.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.