我试图解决一个简单的程序。我插入下面的代码。
puts "By how much degrees you want to trun right?"
print "Enter a number: "
angle=gets.chomp
puts "Got it...now turn right"
if angle < 25
puts "This #{angle} degree is too low to turn right"
elsif angle < 50 && angle >25
puts "This #{angle} degree is somewhat better, but can do better"
elsif angle < 75 && angle >50
puts "This #{angle} is somewhat steep."
elsif angle <= 100 && angle >75
puts "This #{angle} is not recommended. It is toooo steep. Reduce it."
else
puts "Start off!"
end
它从第6行闪烁“参数错误”。请帮助我。我附上了错误的屏幕截图。
答案 0 :(得分:1)
您无法将字符串与整数进行比较。您需要将字符串转换为整数
if angle.to_i < 25
或在读取值后立即转换为整数:
input = gets
# Check if only numerics were entered
if input =~ /^\d+$/
angle = input.to_i
else
puts "Please enter numeric value"
exit
end