R_Code-4.r
Problem Statement
R_Code-4.r
Write a standard if...else block that checks if a variable named age is greater than 18. If the condition is true, print "You are eligible to vote.", otherwise print "You cannot vote.".
Source Code
r
# Author: Amit Dutta (amitdutta4255@gmail.com) | Date: 19 Mar 2026
# Repo: https://github.com/notamitgamer/bsc
# License: MIT
# Write a standard if...else block that checks if a variable named
# age is greater than 18. If the condition is true, print "You are eligible to vote.",
# otherwise print "You cannot vote.".
age <- -1
if (age < 0) {
print("Not a valid age.")
} else if (age < 18) {
print("Not eligible to vote.")
} else {
print("Eligible to vote.")
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
● Author - Amit Dutta · Updated - 19 Mar 2026