# I just can't understand why this program is not working

**URL:** <https://www.ruby-forum.com/t/i-just-cant-understand-why-this-program-is-not-working/172762>\
**Category:** Ruby\
**Created:** [July 27, 2009, 7:03pm UTC](https://www.ruby-forum.com/t/i-just-cant-understand-why-this-program-is-not-working/172762 "2009-07-27T19:03:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![prateekagarwal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b38774/32.png) [@prateekagarwal](https://www.ruby-forum.com/u/prateekagarwal)\
**Post date:** [July 27, 2009, 7:03pm UTC](https://www.ruby-forum.com/t/i-just-cant-understand-why-this-program-is-not-working/172762/1 "2009-07-27T19:03:47Z")

</div>

Can someone please tell me what the problem with this program is?

When I run it, I am able to input the values but I am not getting any  
results. It just hangs after that. Then I press ‘ctrl+c’, and I get some  
‘interrupt’ error.  
Please help?

---

<div class="post-metadata">

**Author:** ![prateekagarwal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b38774/32.png) [@prateekagarwal](https://www.ruby-forum.com/u/prateekagarwal)\
**Post date:** [July 27, 2009, 7:13pm UTC](https://www.ruby-forum.com/t/i-just-cant-understand-why-this-program-is-not-working/172762/2 "2009-07-27T19:13:32Z")

</div>

On Tue, 28 Jul 2009, Prateek A. wrote:

> Can someone please tell me what the problem with this program is?
> 
> When I run it, I am able to input the values but I am not getting any  
> results. It just hangs after that. Then I press ‘ctrl+c’, and I get some  
> ‘interrupt’ error.  
> Please help?
> 
> Attachments:  
> [http://www.ruby-forum.com/attachment/3906/q2.rb](http://www.ruby-forum.com/attachment/3906/q2.rb)

basically, you are not passing ints, you’re passing strings. And they  
will never equal.

sidelength.to\_i returns the integer representation of sidelength,  
however  
it does not change sidelength.

Likewise noofiterations.

Then when you do your comparison, it will never evaluate as true, so you  
never break out of the loop.

Matt

---

<div class="post-metadata">

**Author:** ![prateekagarwal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b38774/32.png) [@prateekagarwal](https://www.ruby-forum.com/u/prateekagarwal)\
**Post date:** [July 27, 2009, 7:17pm UTC](https://www.ruby-forum.com/t/i-just-cant-understand-why-this-program-is-not-working/172762/3 "2009-07-27T19:17:20Z")

</div>

Matthew K. Williams wrote:

> On Tue, 28 Jul 2009, Prateek A. wrote:
> 
> > Can someone please tell me what the problem with this program is?
> > 
> > When I run it, I am able to input the values but I am not getting any  
> > results. It just hangs after that. Then I press ‘ctrl+c’, and I get some  
> > ‘interrupt’ error.  
> > Please help?
> > 
> > Attachments:  
> > [http://www.ruby-forum.com/attachment/3906/q2.rb](http://www.ruby-forum.com/attachment/3906/q2.rb)
> 
> basically, you are not passing ints, you’re passing strings. And they  
> will never equal.
> 
> sidelength.to\_i returns the integer representation of sidelength,  
> however  
> it does not change sidelength.
> 
> Likewise noofiterations.
> 
> Then when you do your comparison, it will never evaluate as true, so you  
> never break out of the loop.
> 
> Matt

Thanks for the help man. Can you tell me how to input ints?

---

<div class="post-metadata">

**Author:** ![prateekagarwal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b38774/32.png) [@prateekagarwal](https://www.ruby-forum.com/u/prateekagarwal)\
**Post date:** [July 27, 2009, 7:22pm UTC](https://www.ruby-forum.com/t/i-just-cant-understand-why-this-program-is-not-working/172762/4 "2009-07-27T19:22:54Z")

</div>

On Tue, 28 Jul 2009, Prateek A. wrote:

> Thanks for the help man. Can you tell me how to input ints?

Here’s one way; there’s more, I’m sure:

irb(main):005:0\> s=gets  
1  
=\> “1\n”  
irb(main):006:0\> s.class  
=\> String  
irb(main):007:0\> s=s.to\_i  
=\> 1  
irb(main):008:0\> s.class  
=\> Fixnum

Matt

---

<div class="post-metadata">

**Author:** ![prateekagarwal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b38774/32.png) [@prateekagarwal](https://www.ruby-forum.com/u/prateekagarwal)\
**Post date:** [July 27, 2009, 7:55pm UTC](https://www.ruby-forum.com/t/i-just-cant-understand-why-this-program-is-not-working/172762/5 "2009-07-27T19:55:48Z")

</div>

Dude, seriously thanks a lot 🙂
