Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1 #!/usr/bin/env ruby
- 2 #tells if a person is young, adult, or an old person
- 3
- 4 #1 ask for age
- 5 puts "Please enter your age"
- 6 age = gets.to_i
- 7
- 8 #2 Process
- 9 #output = if age < 10
- 10 # "Youre a young person"
- 11 #elsif age < 19
- 12 # "its a teenager"
- 13 #elsif age < 45
- 14 # "its an adult"
- 15 #else
- 16 # "You must be ancient"
- 17 #end
- 18 #
- 19 #puts output
- 20
- 21 #The Switch Statement: Ruby Style
- 22 output = case age
- 23 when age < 10 then "Youre a young person"
- 24 when age <19 then "Youre a teenager"
- 25 when age < 45 then "Youre an adult"
- 26 else "You must be ancient"
- 27 end
- 28
- 29 puts "If you are #{age} then #{output}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement