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
# 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
2
3
4
5
6
7
8
9
10
11
12