# Please Help I'm new in Ruby -- Input Problem

**URL:** <https://www.ruby-forum.com/t/please-help-im-new-in-ruby-input-problem/181663>\
**Category:** Ruby\
**Created:** [January 15, 2010, 4:35pm UTC](https://www.ruby-forum.com/t/please-help-im-new-in-ruby-input-problem/181663 "2010-01-15T16:35:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![nollysizzle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/4bbf92/32.png) [@nollysizzle](https://www.ruby-forum.com/u/nollysizzle)\
**Post date:** [January 15, 2010, 4:35pm UTC](https://www.ruby-forum.com/t/please-help-im-new-in-ruby-input-problem/181663/1 "2010-01-15T16:35:35Z")

</div>

Hi,

I’m interested to learn this language. I’m using Eclipse with Ruby  
plugin. I encountered this problem. I place this code (got from an  
internet site):

def addtwo(a, b)  
a + b; # return a + b  
end

print "Please enter number 1 : ";

val1 = gets;  
print "Please enter number 2 : ";  
val2 = gets;  
print "Answer : " , (val1.to\_i + val2.to\_i), “\n”;

It actually works! But the this is when I run this, the console doesn’t  
show the first print (print "Please enter number 1 : "😉 it waits for me  
to place a number, then another number before it shows the print. See  
below:

1  
2  
Please enter number 1 : Please enter number 2 : Answer : 3

Please help me.  
Thank you!  
Nolly

---

<div class="post-metadata">

**Author:** ![nollysizzle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/4bbf92/32.png) [@nollysizzle](https://www.ruby-forum.com/u/nollysizzle)\
**Post date:** [January 15, 2010, 5:07pm UTC](https://www.ruby-forum.com/t/please-help-im-new-in-ruby-input-problem/181663/2 "2010-01-15T17:07:46Z")

</div>

Nolly Mejia wrote:

> Hi,
> 
> I’m interested to learn this language. I’m using Eclipse with Ruby  
> plugin. I encountered this problem. I place this code (got from an  
> internet site):
> 
> def addtwo(a, b)  
> a + b; # return a + b  
> end
> 
> print "Please enter number 1 : ";
> 
> val1 = gets;  
> print "Please enter number 2 : ";  
> val2 = gets;  
> print "Answer : " , (val1.to\_i + val2.to\_i), “\n”;

Whatever site this code came from can be considered untrustworthy.  
Clearly, whoever wrote it doesn’t know enough about Ruby to know that  
it’s considered poor style to put semicolons at the end of lines. And  
if they don’t know something that basic, what else are they screwing up?

> It actually works! But the this is when I run this, the console doesn’t  
> show the first print (print "Please enter number 1 : "😉 it waits for me  
> to place a number, then another number before it shows the print. See  
> below:
> 
> 1  
> 2  
> Please enter number 1 : Please enter number 2 : Answer : 3
> 
> Please help me.

Your console output is probably being buffered by line. Try putting a  
\n in the string and see if that solves the problem.

> Thank you!  
> Nolly

Best,  
–Â  
Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![nollysizzle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/4bbf92/32.png) [@nollysizzle](https://www.ruby-forum.com/u/nollysizzle)\
**Post date:** [January 15, 2010, 5:37pm UTC](https://www.ruby-forum.com/t/please-help-im-new-in-ruby-input-problem/181663/3 "2010-01-15T17:37:56Z")

</div>

On Sat, 16 Jan 2010, Nolly Mejia wrote:

> > [http://www.marnen.org](http://www.marnen.org)  
> > Please enter number 1 :  
> > Please enter number 2 :  
> > Answer : 5
> 
> I have Final Report on my class, regarding aspiring programming  
> language. I hope some one can find way.

Try replacing print with puts

It does look as though your output is being buffered. Which is odd.  
You may need to add explicit STDOUT.flush after your print statements.

Matt

---

<div class="post-metadata">

**Author:** ![nollysizzle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/4bbf92/32.png) [@nollysizzle](https://www.ruby-forum.com/u/nollysizzle)\
**Post date:** [January 15, 2010, 7:09pm UTC](https://www.ruby-forum.com/t/please-help-im-new-in-ruby-input-problem/181663/4 "2010-01-15T19:09:40Z")

</div>

Matthew K. Williams wrote:

> On Sat, 16 Jan 2010, Nolly Mejia wrote:
> 
> > > [http://www.marnen.org](http://www.marnen.org)  
> > > Please enter number 1 :  
> > > Please enter number 2 :  
> > > Answer : 5
> > 
> > I have Final Report on my class, regarding aspiring programming  
> > language. I hope some one can find way.
> 
> Try replacing print with puts
> 
> It does look as though your output is being buffered. Which is odd.  
> You may need to add explicit STDOUT.flush after your print statements.
> 
> Matt

Hi Matt,

GREAT! It works…thanks for helping me.=D

---

<div class="post-metadata">

**Author:** ![nollysizzle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/4bbf92/32.png) [@nollysizzle](https://www.ruby-forum.com/u/nollysizzle)\
**Post date:** [January 15, 2010, 7:19pm UTC](https://www.ruby-forum.com/t/please-help-im-new-in-ruby-input-problem/181663/5 "2010-01-15T19:19:12Z")

</div>

On Sat, 16 Jan 2010, Nolly Mejia wrote:

> > 
> 
> GREAT! It works…thanks for helping me.=D  
> Most welcome. Hope you enjoy your exploration of Ruby!  
> Matt

---

<div class="post-metadata">

**Author:** ![nollysizzle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/4bbf92/32.png) [@nollysizzle](https://www.ruby-forum.com/u/nollysizzle)\
**Post date:** [January 15, 2010, 5:28pm UTC](https://www.ruby-forum.com/t/please-help-im-new-in-ruby-input-problem/181663/6 "2010-01-15T17:28:18Z")

</div>

> Your console output is probably being buffered by line. Try putting a  
> \n in the string and see if that solves the problem.
> 
> > Thank you!  
> > Nolly
> 
> Best,  
> –Â  
> Marnen Laibow-Koser  
> [http://www.marnen.org](http://www.marnen.org)  
> removed\_email\_address@domain.invalid

Hi Marnen,

Thank you for helping I really appreciate, but I still have the same  
problem.  
Here’s the output when I placed \n

3  
2  
Please enter number 1 :  
Please enter number 2 :  
Answer : 5

I have Final Report on my class, regarding aspiring programming  
language. I hope some one can find way.
