LEARN RUBY ON THE MAC
LEARN RUBY ON THE MAC

Script 1 Solution

#!/bin/ruby
puts “convert from mile or km?”
theScale = gets
puts “how many?”
theNumber = gets

theAnswer = (theNumber.to_i / 5.0) * 8 if theScale.chomp == “mile”
theAnswer = (theNumber.to_i / 8.0) * 5 if theScale.chomp == “km”

theUnit = “miles” if theScale.chomp == “km”
theUnit = “kms” if theScale.chomp == “mile”

puts “The answer is #{theAnswer} #{theUnit}”

 

Back to Script 1 post…

Print Print | Sitemap
© Learn Ruby on the Mac