To decide person eligible for voting or not
In this tutorial we are going to see one simple program that is to check whether the person is eligible for voting or not.
For checking the eligibility for voting we have to write simple condition.
As we know, as per government the persons whose age is greater than 18 are eligible to give the vote and below age 18 are not allowed to vote.
So , using simple condition statement we check this condition and decide who is eligible and who is not eligible.
We can implement this program in two ways.
- By taking age input from user.
- By taking date of birth input from user.
Using first method logic :-
- First we take the input the age of person to check eligibility for voting.
- We write the condition that is input > 18 then , if true we print person is eligible for voting
- 3 else person is not eligible.
Using second method logic :-
- Take input date of birth from user.
- Calculate current age by date of birth of user.
- Now compare age of person , age > 18
- If true , then print person is eligible for voting.
- Else person is not eligible for voting.
C program to check person is eligible for voting or not
int age ;
//take input age from user
printf("Enter the age of the person: ");
//check voting eligibility
printf("person is eligible for voting");
printf("person is not eligibal for voting\n");
Enter the age of the person: 21
person is eligible for voting