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

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

···

--
Posted via http://www.ruby-forum.com/.

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

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/\.

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

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/\.

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?

Dude, seriously thanks a lot :slight_smile:

···

--
Posted via http://www.ruby-forum.com/.