J
Jay Bornhoft
I wrote this little prog giving the user two choices.
I would really appreciate any advice on how I can improve anything about
this program (structure, layout, etc)
Many thanks!
Code:
-----
# Name: 2choices-jb.rb
# Date: December 2006
# Author: Jason Bornhoft
# Email: (e-mail address removed)
puts ""
puts "Conversion Program"
puts "------------------\n"
puts "Would you like to convert:"
puts "1. F to C"
puts "2. C to F"
puts"Enter your choice now: "
choice = gets.chomp.to_i
if choice == 1
puts "Enter a temperature in F:"
fahr = gets.chomp.to_f
cent = ( (fahr - 32) / 1.8 )
puts fahr.to_s + " F is " + cent.round.to_s + " C."
elsif choice == 2
puts "Enter a temperature in C:"
cent = gets.chomp.to_f
fahr = ( (cent * 1.8) + 32 )
puts cent.to_s + " C is " + fahr.round.to_s + " F."
else
puts "That is a not a valid choice. Good bye!"
end
I would really appreciate any advice on how I can improve anything about
this program (structure, layout, etc)
Many thanks!
Code:
-----
# Name: 2choices-jb.rb
# Date: December 2006
# Author: Jason Bornhoft
# Email: (e-mail address removed)
puts ""
puts "Conversion Program"
puts "------------------\n"
puts "Would you like to convert:"
puts "1. F to C"
puts "2. C to F"
puts"Enter your choice now: "
choice = gets.chomp.to_i
if choice == 1
puts "Enter a temperature in F:"
fahr = gets.chomp.to_f
cent = ( (fahr - 32) / 1.8 )
puts fahr.to_s + " F is " + cent.round.to_s + " C."
elsif choice == 2
puts "Enter a temperature in C:"
cent = gets.chomp.to_f
fahr = ( (cent * 1.8) + 32 )
puts cent.to_s + " C is " + fahr.round.to_s + " F."
else
puts "That is a not a valid choice. Good bye!"
end