Determine Voting Eligibility in C
Determine Voting Eligibility in C
Here's a simple C program to determine whether a person is eligible to vote based on their age:
#include <stdio.h>
int main() {
int age;
// Ask the user to enter their age
printf("Enter your age: ");
scanf("%d", &age);
// Check if the person is eligible to vote
if (age >= 18) {
printf("You are eligible to vote.\\n");
} else {
printf("You are not eligible to vote.\\n");
}
return 0;
}
Explanation:
- The program first prompts the user to input their age.
- It then checks if the age is 18 or older. If it is, the program prints that the person is eligible to vote. Otherwise, it indicates that they are not eligible to vote.
- The if
statement is used to compare the user's age with 18, which is the common voting age in many countries.
Comments
Post a Comment