Menu driven program for Voting System
In this article, we will write a menu-driven program to implement the Voting System. The program must contain the following properties:
- Cast votes.
- Display the count of votes of each candidate.
- Display the name of the candidate who has the most votes.
Approach: Follow the steps below to solve the problem:
- Provide the following options to the person who is accessing as shown below:
- Vote for your favorite Candidate.
- Check the number of votes of each Candidate.
- Check the candidate who is leading and then Exit.
- The user chooses one of the options.
- If the user chooses 1, then the list of candidates is displayed and the user can now choose from this list of candidates.
- If the user chooses 2, then the list of candidates along with their current number of votes is displayed.
- If the user chooses 3, the name of the candidate with the maximum number of votes is displayed. If there is more than one candidate with maximum votes, display an error message stating “No winner”.
- This program continues until the user chooses 0 to exit().
Below is the implementation of the above approach: