I'm trying to catch the difference between a numeric string vs. an arbitrary string:
'0'.to_f
#=> 0.0
'hello'.to_f
#=> 0.0
Both of the above return a Float
. How do I catch the difference if the user inputs the actual value '0'
or if the user inputs the value 'hello'
?
I am trying to create a simple Celsius to Fahrenheit calculator. If the user inputs "hello"
the program should output Please type in a number:
but if the user types in 0
then the program should output the correct Fahrenheit calculation.