返回顶部

收藏

华氏到摄氏的转换

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

相关聚客文章
  1. Alex Wood 发表 2014-10-15 13:06:29 Deploying Ruby on Rails Applications to AWS OpsWor
  2. Alex Wood 发表 2014-10-22 12:04:19 Caching the Rails Asset Pipeline with Amazon Cloud
  3. Trevor Rowe 发表 2014-11-18 19:04:17 Using Resources
  4. Trevor Rowe 发表 2014-11-20 19:04:22 Waiters
  5. Trevor Rowe 发表 2014-11-20 19:04:22 Waiters
  6. Trevor Rowe 发表 2014-11-26 19:04:20 Client Response Stubs
  7. Alex Wood 发表 2014-12-02 17:32:13 AWS re:Invent 2014 Ruby Recap
  8. Alex Wood 发表 2014-12-10 17:20:18 Using Amazon RDS with Ruby on Rails and AWS OpsWor
  9. Trevor Rowe 发表 2015-01-28 17:48:41 Upcoming Stable Release of AWS SDK for Ruby – Vers
  10. Trevor Rowe 发表 2015-02-05 23:46:12 Announcing V2 of the AWS SDK for Ruby
  11. Trevor Rowe 发表 2015-02-13 00:00:22 Amazon DynamoDB Document API in Ruby (Part 1 – Pro
  12. Trevor Rowe 发表 2015-02-18 21:28:00 Amazon DynamoDB Document API in Ruby (Part 2 – Con

发表评论