Salve sono nuovo,
ho appena iniziato a scrivere in Ruby. Ho scritto questo:
class ConvertTemperature
def celsiusToFahrenheit(celsius)
fahrenheit = ((celsius - 32.0) / 180.0) * 100.0
return fahrenheit
end
def fahrenheitToCelsius(fahrenheit)
celsius = ((fahrenheit + 32.0) / 100.0)* 180.0
return celsius
end
end
puts "Temperature Converter"
puts ""
puts "Scegli un operazione:"
puts "1. Da Celsius a Fahrenheit"
puts "2. Da Fahrenheit a Celsius"
operazione = gets
if operazione == 1
puts "Scrivi una temperatura in gradi Celsius:"
convert = ConvertTemperature.new
tempconv = gets
fah = convert.celsiusToFahrenheit(tempconv.to_i)
puts ""
puts "Temperatura in Fahrenheit:"
puts fah
end
if operazione == 2
puts "Scrivi una temperatura in gradi Fahrenheit:"
convert = ConvertTemperature.new
tempconv = gets
cel = convert.fahrenheitToCelsius(tempconv.to_i)
puts ""
puts "Temperatura in Celsius:"
puts cel
end
All'avvio con l'interprete, se scrivo 1 o 2, il programma termina l'esecuzione senza fare ciò che è stato scritto nelle istruzioni if. Perchè?