返回顶部

收藏

华氏到摄氏的转换

更多
#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

收藏

0人收藏

支持

0

反对

0

发表评论