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

**URL:** <https://rubytalk.org/t/i-just-cant-understand-why-this-program-is-not-working/54632>\
**Category:** ruby-talk\
**Created:** [27 July 2009 17:03 UTC](https://rubytalk.org/t/i-just-cant-understand-why-this-program-is-not-working/54632 "2009-07-27T17:03:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Prateek\_Agarwal](https://avatars.discourse-cdn.com/v4/letter/p/c37758/32.png) [@Prateek\_Agarwal](https://rubytalk.org/u/Prateek_Agarwal)\
**Post date:** [27 July 2009 17:03 UTC](https://rubytalk.org/t/i-just-cant-understand-why-this-program-is-not-working/54632/1 "2009-07-27T17:03:50Z")

</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?

Attachments:  
[http://www.ruby-forum.com/attachment/3906/q2.rb](http://www.ruby-forum.com/attachment/3906/q2.rb)

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Matt\_Williams](https://avatars.discourse-cdn.com/v4/letter/m/a698b9/32.png) [@Matt\_Williams](https://rubytalk.org/u/Matt_Williams)\
**Post date:** [27 July 2009 17:12 UTC](https://rubytalk.org/t/i-just-cant-understand-why-this-program-is-not-working/54632/2 "2009-07-27T17:12:59Z")

</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?
> 
> 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

> **···**
>
> On Tue, 28 Jul 2009, Prateek Agarwal wrote:
> 
> > --  
> > Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Prateek\_Agarwal](https://avatars.discourse-cdn.com/v4/letter/p/c37758/32.png) [@Prateek\_Agarwal](https://rubytalk.org/u/Prateek_Agarwal)\
**Post date:** [27 July 2009 17:17 UTC](https://rubytalk.org/t/i-just-cant-understand-why-this-program-is-not-working/54632/3 "2009-07-27T17:17:23Z")

</div>

Matthew K. Williams wrote:

> **···**
>
> > On Tue, 28 Jul 2009, Prateek Agarwal 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?  
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Matt\_Williams](https://avatars.discourse-cdn.com/v4/letter/m/a698b9/32.png) [@Matt\_Williams](https://rubytalk.org/u/Matt_Williams)\
**Post date:** [27 July 2009 17:22 UTC](https://rubytalk.org/t/i-just-cant-understand-why-this-program-is-not-working/54632/4 "2009-07-27T17:22:17Z")

</div>

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

> **···**
>
> On Tue, 28 Jul 2009, Prateek Agarwal wrote:
> 
> > Thanks for the help man. Can you tell me how to input ints?

---

<div class="post-metadata">

**Author:** ![Prateek\_Agarwal](https://avatars.discourse-cdn.com/v4/letter/p/c37758/32.png) [@Prateek\_Agarwal](https://rubytalk.org/u/Prateek_Agarwal)\
**Post date:** [27 July 2009 17:55 UTC](https://rubytalk.org/t/i-just-cant-understand-why-this-program-is-not-working/54632/5 "2009-07-27T17:55:54Z")

</div>

Dude, seriously thanks a lot 🙂

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
