c-programs-basics
We are going to write a program in c which can check if the candidate is eligible to vote or not. We can do this by using a simple if-else statement.

C Program For Checking Voter Eligibility

#include<stdio.h>
#include<conio.h>
void main()
{
int age;
char name[50]; // or *name
clrscr();

 printf("\n Type the Name of the candidate: ");
 gets(name);

 printf("\n Enter The Age : ");
 scanf("%d",&age);

 if(age>=18)
  {
    printf("\n %s is Eligible for Vote",name);
  }
 else
  {
    printf("\n %s is Not Eligible for Vote",name);
  }

 getch();
}


Output :

Output-C-Program-Eligible-For-Vote

Output-Not-Eligible-For-Vote







In the above program, we have declared a variable 'age' for age and a character string 'name[50]' for the name of the candidate.
Then we get the values of name from the user using the gets() function. We can also use the scanf() function to get the string values from the user as we have used it to get the value of age. But the problem with scanf() is you can't get spaces in it. Meaning if a user Enters: 'Name' 'Surname' only the Value of 'Name' will get stored in the variable. 
Now to decide if a person is eligible for voting or not we have simply used an if-else statement.
Similar programs we can do using if-else statment : 

1. Find Even Or Odd Number

2. Find Positive Or Negative Number

3. Find Greatest and Smallest Number
Here in India the eligibility criteria for a candidate to vote is the person should be 18 years of age or greater. So we will Check the age is greater than or equal to 18. (You can change this condition according to your country and regulations.)
If the Age is less than 18 that person is not eligible for vote else the person is eligible for voting.

In this way, we can decide whether a person is eligible to vote or not in c programming.