Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Another newbie question

Reply
Thread Tools

Another newbie question

 
 
len
Guest
Posts: n/a
 
      08-12-2005
I am trying to write a small little program that will currently run in
a command window (I will convert it later to GUI).

How do I request input from the user such as:

>>Please enter dollar amount:


I would like the prompt to display and the user to be able to enter the
data after the prompt. I thought "gets" would do it but I don't
understand how to get the prompt to display.

Thanks
Len Sumnler

 
Reply With Quote
 
 
 
 
david@vallner.net
Guest
Posts: n/a
 
      08-12-2005
Cit=E1t len <(E-Mail Removed)>:

> I am trying to write a small little program that will currently run in
> a command window (I will convert it later to GUI).
>=20
> How do I request input from the user such as:
>=20
> >>Please enter dollar amount:

>=20
> I would like the prompt to display and the user to be able to enter the
> data after the prompt. I thought "gets" would do it but I don't
> understand how to get the prompt to display.
>=20
> Thanks
> Len Sumnler
>=20
>=20
>=20



Well, this isn't BASIC, gets isn't supposed to display a prompt. Go like =
this:

puts ">>>Please enter dollar amount:"
amount =3D gets

David Vallner


 
Reply With Quote
 
 
 
 
David A. Black
Guest
Posts: n/a
 
      08-12-2005
--8323328-1636550047-1123853742=:12576
Content-Type: MULTIPART/MIXED; BOUNDARY="8323328-1636550047-1123853742=:12576"

This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.

--8323328-1636550047-1123853742=:12576
Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed
Content-Transfer-Encoding: QUOTED-PRINTABLE

Hi --

On Fri, 12 Aug 2005 http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> Cit=E1t len <(E-Mail Removed)>:
>
>> I am trying to write a small little program that will currently run in
>> a command window (I will convert it later to GUI).
>>
>> How do I request input from the user such as:
>>
>>>> Please enter dollar amount:

>>
>> I would like the prompt to display and the user to be able to enter the
>> data after the prompt. I thought "gets" would do it but I don't
>> understand how to get the prompt to display.
>>
>> Thanks
>> Len Sumnler
>>
>>
>>

>
>
> Well, this isn't BASIC, gets isn't supposed to display a prompt. Go like =

this:
>
> puts ">>>Please enter dollar amount:"
> amount =3D gets


Or use print instead of puts, if you want the input on the same line
as the prompt.


David

--=20
David A. Black
(E-Mail Removed)
--8323328-1636550047-1123853742=:12576--
--8323328-1636550047-1123853742=:12576--


 
Reply With Quote
 
daz
Guest
Posts: n/a
 
      08-12-2005

len wrote:
>
> How do I request input from the user such as:
>
> >>Please enter dollar amount:

>
> I would like the prompt to display and the user to be able to enter the
> data after the prompt. I thought "gets" would do it but I don't
> understand how to get the prompt to display.
>



STDOUT.sync=true
print '>> Please enter amount: $'
resp = STDIN.gets.chomp
puts resp # echo input
puts "\nYour acount balance is below $" << resp << " "

#-> Please enter amount: $12
#->
#-> Your acount balance is below $12


daz



 
Reply With Quote
 
Brian Schröder
Guest
Posts: n/a
 
      08-12-2005
On 12/08/05, daz <(E-Mail Removed)> wrote:
>=20
> len wrote:
> >
> > How do I request input from the user such as:
> >
> > >>Please enter dollar amount:

> >
> > I would like the prompt to display and the user to be able to enter the
> > data after the prompt. I thought "gets" would do it but I don't
> > understand how to get the prompt to display.
> >

>=20
>=20
> STDOUT.sync=3Dtrue
> print '>> Please enter amount: $'
> resp =3D STDIN.gets.chomp
> puts resp # echo input
> puts "\nYour acount balance is below $" << resp << " "
>=20
> #-> Please enter amount: $12
> #->
> #-> Your acount balance is below $12
>=20
>=20
> daz
>=20
>=20
>=20
>=20
>=20


Or use the readline library, there you can even supply the prompt and
you get a ton of extras.

regards,

Brian

--=20
http://ruby.brian-schroeder.de/

Stringed instrument chords: http://chordlist.brian-schroeder.de/


 
Reply With Quote
 
Bill Atkins
Guest
Posts: n/a
 
      08-12-2005
STDOUT.sync =3D true isn't necessary in that snippet. Even though you
haven't output a newline, the outbuffer will get flushed as soon as
you call gets.

Bill

On 8/12/05, daz <(E-Mail Removed)> wrote:
>=20
> len wrote:
> >
> > How do I request input from the user such as:
> >
> > >>Please enter dollar amount:

> >
> > I would like the prompt to display and the user to be able to enter the
> > data after the prompt. I thought "gets" would do it but I don't
> > understand how to get the prompt to display.
> >

>=20
>=20
> STDOUT.sync=3Dtrue
> print '>> Please enter amount: $'
> resp =3D STDIN.gets.chomp
> puts resp # echo input
> puts "\nYour acount balance is below $" << resp << " "
>=20
> #-> Please enter amount: $12
> #->
> #-> Your acount balance is below $12
>=20
>=20
> daz
>=20
>=20
>=20
>=20
>=20



--=20
Bill Atkins


 
Reply With Quote
 
len
Guest
Posts: n/a
 
      08-12-2005
len wrote:
> I am trying to write a small little program that will currently run in
> a command window (I will convert it later to GUI).
>
> How do I request input from the user such as:
>
> >>Please enter dollar amount:

>
> I would like the prompt to display and the user to be able to enter the
> data after the prompt. I thought "gets" would do it but I don't
> understand how to get the prompt to display.
>
> Thanks
> Len Sumnler


Thanks everyone for your responses. At this time, and with my level of
experience (none), I think the option I am looking for is the "puts"
command.

Again thanks everyone for your responses I have copied all of them for
future reference.

Len Sumnler

 
Reply With Quote
 
Julian Leviston
Guest
Posts: n/a
 
      08-12-2005
You'd probably want

puts "Please enter dollar amount":
gets line


Julian.


On 13/08/2005, at 12:41 AM, len wrote:

> len wrote:
>
>> I am trying to write a small little program that will currently
>> run in
>> a command window (I will convert it later to GUI).
>>
>> How do I request input from the user such as:
>>
>>
>>>> Please enter dollar amount:
>>>>

>>
>> I would like the prompt to display and the user to be able to
>> enter the
>> data after the prompt. I thought "gets" would do it but I don't
>> understand how to get the prompt to display.
>>
>> Thanks
>> Len Sumnler
>>

>
> Thanks everyone for your responses. At this time, and with my
> level of
> experience (none), I think the option I am looking for is the "puts"
> command.
>
> Again thanks everyone for your responses I have copied all of them for
> future reference.
>
> Len Sumnler
>
>
>




 
Reply With Quote
 
daz
Guest
Posts: n/a
 
      08-12-2005

Bill Atkins wrote:

> STDOUT.sync = true isn't necessary in that snippet. Even though you
> haven't output a newline, the outbuffer will get flushed as soon as
> you call gets.



That's not a feature of Ruby 1.8.2
You may be describing *nix behaviour ?

On Windows, it looks as if the program is hanging unless #sync of #flush
is used.

[What's worrying is that I can't manage to spell acccount]


daz



 
Reply With Quote
 
David A. Black
Guest
Posts: n/a
 
      08-12-2005
Hi --

On Fri, 12 Aug 2005, Julian Leviston wrote:

> You'd probably want
>
> puts "Please enter dollar amount":
> gets line


I doubt it, unless you've got some reason to expect the input to
terminate with whatever line contains


David

> Julian.
>
>
> On 13/08/2005, at 12:41 AM, len wrote:
>
>> len wrote:
>>
>>> I am trying to write a small little program that will currently run in
>>> a command window (I will convert it later to GUI).
>>>
>>> How do I request input from the user such as:
>>>
>>>
>>>>> Please enter dollar amount:
>>>>>
>>>
>>> I would like the prompt to display and the user to be able to enter the
>>> data after the prompt. I thought "gets" would do it but I don't
>>> understand how to get the prompt to display.
>>>
>>> Thanks
>>> Len Sumnler
>>>

>>
>> Thanks everyone for your responses. At this time, and with my level of
>> experience (none), I think the option I am looking for is the "puts"
>> command.
>>
>> Again thanks everyone for your responses I have copied all of them for
>> future reference.
>>
>> Len Sumnler
>>
>>
>>

>
>


--
David A. Black
(E-Mail Removed)


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Another basic question: How to call and show one Web Form from another Web Form? Rob R. Ainscough ASP .Net Web Controls 3 06-14-2005 03:56 PM
another newbie question from another newbie.... Lee UK VOIP 4 05-17-2005 04:10 PM
Another newbie question re: STDERR and IPC::open3(), nowait() and zombies Dave Newberry Perl 0 10-17-2004 06:41 PM
dumb newbie question (or newbie dumb question) Jerry C. Perl Misc 8 11-23-2003 04:11 AM
another newbie question about vhdl Max VHDL 2 09-01-2003 03:07 PM



Advertisments