R_Code-4.r ​
Metadata ​
- Author — Amit Dutta (amitdutta4255@gmail.com)
- Last updated — 19 Mar 2026
- License — MIT
Problem Statement ​
Problem Statement
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 ​
Printing the code
To print this file, open it on GitHub and click Raw before printing, or use the Download Raw button above and print directly from that page.
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