# I need help debugging my program

**URL:** <https://www.ruby-forum.com/t/i-need-help-debugging-my-program/123322>\
**Category:** Ruby\
**Created:** [December 16, 2007, 11:48am UTC](https://www.ruby-forum.com/t/i-need-help-debugging-my-program/123322 "2007-12-16T11:48:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![phrak](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/d2c977/32.png) [@phrak](https://www.ruby-forum.com/u/phrak)\
**Post date:** [December 16, 2007, 11:48am UTC](https://www.ruby-forum.com/t/i-need-help-debugging-my-program/123322/1 "2007-12-16T11:48:21Z")

</div>

I’m new to Ruby and I’m trying out a very basic user input program. The  
codes below and also I’ve indicated the line giving me grief.

puts “What is your name?”  
name = gets.chomp  
puts “How old are you?”  
age = gets.chomp  
age.to\_s  
puts “What year is it?”  
year = gets.chomp  
birth = year -= age #\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
puts name + " is " + age + " and was born in " + birth

Any help you could give me would be appreciated. Thanks!

---

<div class="post-metadata">

**Author:** ![phrak](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/d2c977/32.png) [@phrak](https://www.ruby-forum.com/u/phrak)\
**Post date:** [December 16, 2007, 12:27pm UTC](https://www.ruby-forum.com/t/i-need-help-debugging-my-program/123322/2 "2007-12-16T12:27:16Z")

</div>

Icarus D. wrote:

> puts “How old are you?”  
> age = gets.chomp  
> age.to\_s

In this line you’re asking ruby to give you a string representation of  
age.  
This is superfluous for two reasons:  
a) You’re not storing the result anywhere or do anything with it. That’s  
like  
if you have a line in your code that just says 2+2 and nothing else.  
to\_s  
doesn’t modify the receiver it just returns a string. If you don’t use  
the  
return value, it does nothing at all.  
b) gets always returns a string, so age is a string. Turning a string  
into a  
string is redundant.

> puts “What year is it?”  
> year = gets.chomp  
> birth = year -= age

Here you’re trying to use the String#- method without previously  
defining it.  
By default it’s not possible in ruby to subtract strings, which is  
pretty  
sensible, cause what would “bla” - “blubb” even mean?

HTH,  
Sebastian

---

<div class="post-metadata">

**Author:** ![phrak](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/d2c977/32.png) [@phrak](https://www.ruby-forum.com/u/phrak)\
**Post date:** [December 16, 2007, 12:29pm UTC](https://www.ruby-forum.com/t/i-need-help-debugging-my-program/123322/3 "2007-12-16T12:29:36Z")

</div>

What does “birth = year -= age” try to do?

Tek
