C Exercises: Detrermine a specific age is eligible for casting the vote
5. Voting Eligibility
Write a C program to read the age of a candidate and determine whether he is eligible to cast his/her own vote.
Visual Presentation:
Sample Solution:
C Code:
#include <stdio.h> // Include the standard input/output header file.
void main()
{
int vote_age; // Declare an integer variable 'vote_age' to store the age of the candidate.
printf("Input the age of the candidate : "); // Prompt the user to input the age of the candidate.
scanf("%d",&vote_age); // Read and store the user's input in 'vote_age'.
if (vote_age<18) // Check if 'vote_age' is less than 18.
{
printf("Sorry, You are not eligible to caste your vote.\n"); // Print a message indicating the candidate is not eligible to vote.
printf("You would be able to caste your vote after %d year.\n",18-vote_age); // Print the number of years until the candidate is eligible to vote.
}
else
printf("Congratulation! You are eligible for casting your vote.\n"); // Print a message indicating the candidate is eligible to vote.
}
Output:
Input the age of the candidate : 21 Congratulation! You are eligible for casting your vote.
Flowchart:
For more Practice: Solve these Related Problems:
- Write a C program to check voting eligibility and output the number of years remaining if the candidate is underage.
- Write a C program to validate age for voting and prompt for an identification number if eligible.
- Write a C program to check voting eligibility using a switch-case structure based on age ranges.
- Write a C program to determine voting eligibility while also verifying citizenship status from user input.
C Programming Code Editor:
Previous: Write a C program to find whether a given year is a leap year or not.
Next: Write a C program to read the value of an integer m and display the value of n is 1 when m is larger than 0, 0 when m is 0 and -1 when m is less than 0.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.