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.
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 = gets
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.
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.
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 = gets
Or use print instead of puts, if you want the input on the same line
as the prompt.
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.
>
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.
>
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.
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.
]
Do this first:
$ sudo gem install highline
Then you can get nice prompts like this:
#!/usr/local/bin/ruby
require "rubygems"
require "highline/import"
dollar_amt = ask("Please enter the dollar amount : ")
Then you can just use dollar_amt however you want and when you rub your program it will prompt for the input and once it gets it it will assign it to dollar_amt. Nice and simple. Thanks to James and Greg.
I doubt it, unless you've got some reason to expect the input to
terminate with whatever line contains
David
···
On Fri, 12 Aug 2005, Julian Leviston wrote:
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.
> 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]
On Sat, 13 Aug 2005, [ISO-8859-1] Brian Schröder wrote:
> a minor correction:
>
> On 12/08/05, Julian Leviston <julian@coretech.net.au> wrote:
>> You'd probably want
>
> - puts "Please enter dollar amount":
> + puts "Please enter dollar amount:"
> gets line
On Sat, 13 Aug 2005, [ISO-8859-1] Brian Schröder wrote:
> a minor correction:
>
> On 12/08/05, Julian Leviston wrote:
>> You'd probably want
>
> - puts "Please enter dollar amount":
> + puts "Please enter dollar amount:"
> gets line
I'm almost certain he actually wants:
line = gets
raise 'almost certain' #
------------------------------------------------------------ Kernel#gets
gets(separator=$/) => string or nil
------------------------------------------------------------------------
Returns (and assigns to $_) the next line from the list of files
in ARGV (or $*), or from standard input if no files are present
on the command line.
[...]
- puts "Please enter dollar amount":
+ puts "Please enter dollar amount:"
gets line
I'm almost certain he actually wants:
line = gets
raise 'almost certain' #
------------------------------------------------------------ Kernel#gets
gets(separator=$/) => string or nil
------------------------------------------------------------------------
Returns (and assigns to $_) the next line from the list of files
in ARGV (or $*), or from standard input if no files are present
on the command line.
[...]
Yes -- hence my original reply:
I doubt it, unless you've got some reason to expect the input to
terminate with whatever line contains
STDIN.gets is safer for this case, I think.
What would be the non-safeness of gets?
David
···
On Sat, 13 Aug 2005, daz wrote:
On Sat, 13 Aug 2005, [ISO-8859-1] Brian Schröder wrote:
> David A. Black wrote:
>
>>
>>> a minor correction:
>>>
>>>> You'd probably want
>>>
>>> - puts "Please enter dollar amount":
>>> + puts "Please enter dollar amount:"
>>> gets line
>>
>> I'm almost certain he actually wants:
>>
>> line = gets
>
>
> raise 'almost certain' #
>
> ------------------------------------------------------------ Kernel#gets
> gets(separator=$/) => string or nil
> ------------------------------------------------------------------------
> Returns (and assigns to $_) the next line from the list of files
> in ARGV (or $*), or from standard input if no files are present
> on the command line.
> [...]
Yes -- hence my original reply:
I doubt it, unless you've got some reason to expect the input to
terminate with whatever line contains
I wasn't referring to your 'separator' note.
> STDIN.gets is safer for this case, I think.
What would be the non-safeness of gets?
David
Kernel#gets has a higher action when ARGV is non-empty.
···
On Sat, 13 Aug 2005, daz wrote:
>> On Sat, 13 Aug 2005, [ISO-8859-1] Brian Schröder wrote:
>>> On 12/08/05, Julian Leviston wrote: