Advertisement
Guest User

Untitled

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