摄氏温度到华氏温度?

时间:2017-09-12 19:44:07

标签: ruby temperature

我在Ruby中编写了以下代码,用于Celsius到Fahrenheit的转换。我一直在收到错误。我确信我仍然不清楚方法的概念,这就是我无法弄明白的原因。

puts "Enter the Degree in c:"
c = gets.chomp

def celsius_fahrenheit (f) 
  return f = ( c * 9 / 5) + 32
end

answer = "The #{celsius_fahrenheit (f)} equivalent is"
puts answer

1 个答案:

答案 0 :(得分:2)

你有几个问题:

  1. Float转换为celsius_fahrenheit
  2. c的签名更改为使用def celsius_fahrenheit(c) c * 9 / 5 + 32 end puts 'Enter C:' c = gets.to_f puts celsius_fahrenheit(c) 作为参数
  3. 不要在方法
  4. 中进行任务

    以下是代码:

    oauth2_access_token
相关问题