Pages

Monday

Program to Check Whether the Person is Eligible to Vote or Not in C | C Program

Here's a C program to check whether the person is eligible to vote or not with output and proper explanation.

# include <stdio.h> 
# include <conio.h> 
void main() 
{ 
 int age ; 
 clrscr() ; 
 printf("Enter the age : ") ; 
 scanf("%d", &age) ; 
 if(age >= 18) 
  printf("\nThe person is eligible to vote.") ; 
 else 
  printf("\nThe person is not eligible to vote.") ; 
 getch() ; 
} 
 
Output of above program is

Enter the age : 35
The person is eligible to vote.

Enter the age : 11
The person is not eligible to vote.


Explanation of above program

Here is an interesting program to check whether a person is eligible to vote or not. This can be easily done using an If-else condition and checking whether the age of that person is greater than or equal to the minimum allowed age for voting (18 years).

So first user enters his/her age than the If-else condition is used to check if the age is greater than or equal to 18 and if it is then the If part is executed otherwise the else part is executed.

4 comments:

  1. I want c program for voting by accepting nationality and age of candidate using nested if statement

    ReplyDelete
  2. How many nationalities you want to include? You could do it using a simple SWITCH block like mentioned in below algorithm:

    char[] nationality: ask for nationality
    int age: ask for age
    int check_age: 0

    switch(nationality)
    case "india":
    check_age = indian_eligibility_age
    case "us":
    check_age = us_eligibility_age
    .
    .
    .
    .
    case "russia":
    check_age = russian_eligibility_age

    end switch

    if age >= check_age
    print eligible
    else
    print not_eligible

    ReplyDelete
  3. i need a programme to find the exact age of a person

    ReplyDelete
  4. num=int(input("enter the age"))
    if num>=18:
    print("eligible for voting")
    else:
    print("not eligible for voting")

    ReplyDelete