![]() |
VOOZH | about |
Write a Menu-driven program to check the eligibility of a person to vote or not.
: The age of the person should be greater than or equal to 18.
A menu-driven program is a type of computer program that allows users to interact with it by selecting options from a menu. Instead of typing commands or code, users navigate through a series of menus that present a list of actions or functions they can perform.
Examples:
Enter your age: 12
Person is not allowed to vote
To continue press Y
To exit press N
Y
Enter your age: 19
Person is allowed to vote
To continue press Y
To exit press N
N
Program Terminated
Approach: Using While looping and If-Else conditioning
The problem can be solved using a while loop which keeps on asking the user to input the age, till the user does not press 'N'. Inside the while loop, the user enters the age and if the age < 18, the user is not eligible to vote else the user is eligible. As soon as the user presses 'N', the control comes out of the while loop and the program gets terminated.
Below is the implementation of the approach:
Output:
Enter your age: 12
Person is not allowed to vote
To continue press Y
To exit press N
Y
Enter your age: 19
Person is allowed to vote
To continue press Y
To exit press N
N
Program Terminated