Ive been trying to make an app, that takes an input... what the app really does, doesn't really matter as my problem is... how do I make my program to know if the user entered a string or a number? so far i made this:
CODE
#This function is just a factorial function.
def fact(n)
a = 1
b = 1
while a <= n
b = b * a
a += 1
end
end
#And this is the function I'm talking about. Its the best i could think of...
def num?(n)
true if (fact(n) != 0) rescue false
end
problem is, the program uses numbers and 0 should be considered a number as well... with this function its not possible.
What I'm asking for is an efficient function to give me a true value if the user got a number and false if its a string...
Pseudocode would be preferable but the function alone would be fine too i guess...
Thanks.
P.S.
This is a ninja
This post has been edited by mmzdaniel: 27 Apr, 2009 - 07:56 AM