how many seconds old am i?

  • Thread starter Austin Delauney
  • Start date
A

Austin Delauney

for some reason line 6 doesnt work.i converted it into a integer but
still i get the error ".
How_old_are_you?.rb:6:in `*': String can't be coerced into Fixnum
(TypeError)
from How_old_are_you?.rb:6
"
the * should work because i tried it. or if someone could tell me how to
do an input as a integer that would be great. but i would see of that
would have to work...
 
A

Alex Stahl

You didn't save the result of .to_i.

That is to say, if you just do:

age.to_i

then that's all the machine does - creates a new int out of 'a'. But it
doesn't hold onto it if you don't tell it to. So you can either assign
it back to itself, somewhere else, or just call .to_i when it's actually
needed:

age = age.to_i

*or*

age_val = age.to_i

*or*

puts 86000*365*age.to_i
 
R

Ryan Davis

puts 86000*365*age.to_i

As much as I dislike doing someone's homework for them... *shudder* I =
can't help being anal about calendrical calculations...

There are 86400 seconds in a day, and a fractional number of days in a =
year (365.242199). You'd be off by more than 2 months for someone my =
age. Probably not a huge deal for something like this, but you'd be =
really late to the eclipse...=
 
A

Albert Schlef

Ryan said:
There are 86400 seconds in a day, and a fractional number of days in a
year (365.242199). You'd be off by more than 2 months for someone my
age.

Are you... 240 years old?

(0.25 days * 240 years = 2 months)
 
P

Phillip Gawlowski

Are you... 240 years old?

(0.25 days * 240 years = 2 months)

You forgot to account for the lack of 400 seconds (6.666... minutes!) a day. ;)

--
Phillip Gawlowski

Though the folk I have met,
(Ah, how soon!) they forget
When I've moved on to some other place,
There may be one or two,
When I've played and passed through,
Who'll remember my song or my face.
 
R

Rick DeNatale

Are you... 240 years old?

(0.25 days * 240 years = 2 months)

That might explain why Ryan seems to get, shall we say, a bit
crotchety at times. <G>

And I thought *I* was old.
--
Rick DeNatale

Help fund my talk at Ruby Conf 2010:http://pledgie.com/campaigns/13677
Blog: http://talklikeaduck.denhaven2.com/
Github: http://github.com/rubyredrick
Twitter: @RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale
 
A

Austin Delauney

As much as I dislike doing someone's homework for them... *shudder* I
can't help being anal about calendrical calculations...
This isn't homework. i was doing a tutorial and it said make a app that
counts the seconds of someone. and i was all like ok! and i did it but i
couldn't figure the last art out. thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top