How do I convert a float to a whole number?

ساخت وبلاگ

Vote count: 0

guys and gals! I'm pretty new to Ruby and I've run across a problem with something that I'm not entirely sure how to work.

As a challenge, a friend told me to create a program that determines whether or not a person can participate in an activity based on their height. If their height in centimeters/inches/whatever is a perfect square, then they can go, if not, they can't. This is what I have now:

print "Input height here:"
def height_input input = gets.to_i input**0.5
end
if height_input.integer? print "Congrats, you're in!"
else print "Sorry, we can't let you in."
end

I'm certain that the last 'if' statement doesn't work the way I want it to because the method retus a float value (example: input=64 => 8.0) and not a normal, whole number integer. If I add a (.to_i) to the end of the method, or if I call the method to make the value an integer, it gives me the first digit of the root in integer form. That isn't bad if I do in fact have a perfect square, but if it's not a perfect square, then I get the same result as if I did. Help?

asked 2 mins ago

- - , .

back soft...
ما را در سایت back soft دنبال می کنید

برچسب : نویسنده : استخدام کار backsoft بازدید : 368 تاريخ : جمعه 30 بهمن 1394 ساعت: 8:14