# Help with beginner code

**URL:** <https://www.ruby-forum.com/t/help-with-beginner-code/100258>\
**Category:** Ruby\
**Created:** [July 28, 2006, 1:32am UTC](https://www.ruby-forum.com/t/help-with-beginner-code/100258 "2006-07-28T01:32:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 28, 2006, 1:32am UTC](https://www.ruby-forum.com/t/help-with-beginner-code/100258/1 "2006-07-28T01:32:41Z")

</div>

Hello everyone. I’m trying to learn to program, and after some  
searching I’ve decided to learn while using Ruby. I’m using the Chris  
Pine guide for now, but I’ve gotten stuck on a simple program I’m  
messing with. Here is what I have:

daysindecade = 365 \* 10  
daysinyear = 365  
hoursinyear = 8760  
hoursindecade = hoursinyear \* 10  
minutesinday = 60 \* 24  
secondsinday = minutesinday \* 60  
secondsinyear = secondsinday \* 365  
secondsindecade = secondsinyear \* 10

puts ‘How old are you?’  
myage = gets.chomp

daysalive = myage \* daysinyear

puts ‘You have been alive ’ + daysalive + ’ days.’

I just would like the program to multiply the age I enter in by 365 to  
give me how many days that person has been alive.

Now I’m guessing that myage is a string, so I thought I’d have to turn  
it into an integer for this to work. So I tried myage.to\_i but I’ve  
still had no luck. Any tips on how to make this work?

Thanks in advance!  
Mark

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 28, 2006, 1:42am UTC](https://www.ruby-forum.com/t/help-with-beginner-code/100258/2 "2006-07-28T01:42:10Z")

</div>

removed\_email\_address@domain.invalid wrote:

> secondsinday = minutesinday \* 60
> 
> I just would like the program to multiply the age I enter in by 365 to  
> give me how many days that person has been alive.
> 
> Now I’m guessing that myage is a string, so I thought I’d have to turn  
> it into an integer for this to work. So I tried myage.to\_i but I’ve  
> still had no luck. Any tips on how to make this work?
> 
> Thanks in advance!  
> Mark

daysalive = myage.to\_i \* daysinyear

puts ‘You have been alive ’ + daysalive.to\_s + ’ days.’  
puts “You have been alive #{ daysalive } days.”

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 28, 2006, 2:01am UTC](https://www.ruby-forum.com/t/help-with-beginner-code/100258/3 "2006-07-28T02:01:48Z")

</div>

> daysalive = myage.to\_i \* daysinyear
> 
> puts ‘You have been alive ’ + daysalive.to\_s + ’ days.’  
> puts “You have been alive #{ daysalive } days.”

Thank you so much! I learned a lot from that.
