środa, 7 maja 2014

user input in ruby with to_i

#!/usr/bin/ruby

print ('Enter your score: ')
score= gets.to_i //without it you always choose invalid score :)
puts "#{score}"
result = case score
   when 0..40 then "Fail"
   when 41..60 then "Pass"
   when 61..70 then "Pass with Merit"
   when 71..100 then "Pass with Distinction"
   else "Invalid Score"
end

puts result

Brak komentarzy:

Prześlij komentarz