华氏到摄氏的转换

2015-05-29 0 364
华氏到摄氏的转换
#PennyBoki @ </dream.in.code>
puts "Please select "
puts 'A for Celsius to Fahrenheit'
puts 'B for Fahrenheit to Celsius'
STDOUT.flush  
string0 = gets.chomp  
if string0 == 'A' || string0 == 'a'
puts 'Enter the temperature in Celsuis'
STDOUT.flush
string1 = gets.chomp
x = string1.to_f
y = 32+(9.0/5)*x
puts 'The temperature in Fahrenheit is '+y.to_s
else
  if string0 == 'B'|| string0 == 'b'
    puts 'Enter the temperature in Fahrenheit'
    STDOUT.flush
    string2 = gets.chomp
    x = string2.to_f
    y = (x-32)*(5.0/9)
    puts 'The temperature in Celsius is '+y.to_s
  else
    puts 'Invalid option.'
  end
end

遇见资源网 ruby 华氏到摄氏的转换 http://www.ox520.com/16359.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务