C Programs | IT Developer
IT Developer

C Programs



Share with a Friend

Decision Making Programs in C

Check whether a person is eligible to vote

Introduction

In many countries, a person is eligible to vote if their age is 18 years or older.

This program will:

  1. Take a person’s age as input.
  2. Check if they are eligible or not using if-else.
  3. Display the appropriate message.

 

C Program: Check Voting Eligibility

C

#include <stdio.h>

 

int main() {

    int age;

 

    // Input age

    printf("Enter your age: ");

    scanf("%d", &age);

 

    // Check eligibility

    if (age >= 18) {

        printf("You are eligible to vote.\n");

    }

    else if (age >= 0 && age < 18) {

        printf("You are not eligible to vote. You must be at least 18 years old.\n");

    }

    else {

        printf("Invalid age entered.\n");

    }

 

    return 0;

}

Output

 
OUTPUT :

Enter your age: 20
You are eligible to vote.

Enter your age: 16
You are not eligible to vote. You must be at least 18 years old.

Enter your age: -5
Invalid age entered.


Explanation

  1. User inputs their age.
  2. If age >= 18, the person is eligible.
  3. If 0 ≤ age < 18, the person is not eligible.
  4. If age is negative or invalid, program displays an error message.