ARGV not working in a simple code

I’m trying to run this program (cToF.rb)
"
def convertCtoF (celsius)
print(celsius.to_s + " degrees celsius is " +
((celsius * 9) / 5 + 32).to_s + " degrees in
fahrenheit\n")
end

convertCtoF(ARGV[0])
"

in windows environment by typing

"
ruby cToF.rb 20
"

to the command file with the purpose of converting the given 20 to
fahrenheits; but ruby gives me an error message:

"
20cToF.rb:3:in convertCtoF': undefined method/’ for
“202020202020202020”:String (NoMethodError)
from cToF.rb:8:in `’
".

ARGV[0] should yield 20 and the program works if I just replace the
ARGV[0] with 20 in the program code so I don’t get why the program wont
work with this code! The problem is probably something very simple -
could you let me know what I’m doing wrong here?? Many thanks!

perhaps:
convertCtoF(ARGV[0].to_f)

ARGV is a array of String…

Ok, this clarified, now it works, many thanks!

Regis d’Aubarede wrote in post #1046932:

perhaps:
convertCtoF(ARGV[0].to_f)

ARGV is a array of String…

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs