-
Notifications
You must be signed in to change notification settings - Fork 94
/
Copy pathVoter_Eligibility_Check.rb
57 lines (48 loc) · 1.57 KB
/
Voter_Eligibility_Check.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# Program for checking voter age
while true
begin
print "Enter your age: "
age = Integer(gets.chomp)
break
rescue ArgumentError
puts "Invalid age entered. Please enter a valid integer age."
end
end
if (18..120).include?(age)
puts "Congratulations!"
puts "You are eligible to vote."
elsif (12...18).include?(age)
puts "You are not yet eligible to vote."
puts "Enjoy your teenage years!"
elsif (0...12).include?(age)
puts "You are too young to vote."
puts "Make the most of your childhood!"
elsif age < 0
puts "Invalid age entered."
puts "Please enter a positive value."
else
puts "You have surpassed the maximum voting age."
puts "Thank you for your contribution to society!"
end
# -------------------------------END---------------------------------
# The program above is very dynamic while the program below is static
# ------------------------------START--------------------------------
print "Enter your age: "
age = gets.chomp.to_i
# Check if the age is within a valid range for voting
if (18..120).include?(age)
puts "Congratulations!"
puts "You are eligible to vote."
elsif (12...18).include?(age)
puts "You are not yet eligible to vote."
puts "Enjoy your teenage years!"
elsif (0...12).include?(age)
puts "You are too young to vote."
puts "Make the most of your childhood!"
elsif age < 0
puts "Invalid age entered."
puts "Please enter a positive value."
else
puts "You have surpassed the maximum voting age."
puts "Thank you for your contribution to society!"
end