Problem Statement:
Write a program that accepts a number (age) and checks whether the person is eligible to vote. A person is eligible if their age is 18 or more.
Example:
Input: 20
Process: Check if 20 ≥ 18 → Eligible
Output: You are eligible to vote.
Approach:
- Take input from the user (or define a variable).
- Use a conditional statement to check if age is 18 or above.
- If yes, print “You are eligible to vote.”
- Otherwise, print “You are not eligible to vote.”
Visualisation:
Explanation:
- ● Accept age as input.
-
● Use
if age >= 18to check eligibility. - ● Show appropriate message based on condition.
- ● Works the same across all languages.
let age = 20;
if (age >= 18) {
console.log("You are eligible to vote.");
} else {
console.log("You are not eligible to vote.");
}
age = 20
if age >= 18:
print("You are eligible to vote.")
else:
print("You are not eligible to vote.")
public class Main {
public static void main(String[] args) {
int age = 20;
if (age >= 18) {
System.out.println("You are eligible to vote.");
} else {
System.out.println("You are not eligible to vote.");
}
}
}
#include <iostream>
using namespace std;
int main() {
int age = 20;
if (age >= 18)
cout << "You are eligible to vote." << endl;
else
cout << "You are not eligible to vote." << endl;
return 0;
}
#include <stdio.h>
int main() {
int age = 20;
if (age >= 18)
printf("You are eligible to vote.\n");
else
printf("You are not eligible to vote.\n");
return 0;
}
using System;
class Program {
static void Main() {
int age = 20;
if (age >= 18)
Console.WriteLine("You are eligible to vote.");
else
Console.WriteLine("You are not eligible to vote.");
}
}
