comp.lang.ada
 help / color / mirror / Atom feed
* Newbie question: input problem
@ 2002-04-10  2:13 Sidney Bhaiji
  2002-04-10  8:22 ` John McCabe
  0 siblings, 1 reply; 3+ messages in thread
From: Sidney Bhaiji @ 2002-04-10  2:13 UTC (permalink / raw)


Hi, 
   I have the following problem...
Consider the following lines of code....

Option: Integer;
strName, strAddress: String(1..50);
length_In, length_In2: Integer;

Put_Line("Please enter an integer according to what you want to do");
Get(Option, 1);New_Line;

if (Option = 3) then
   Put_Line("Please enter your name");
   Get(strName, length_In); New_Line;
   Put_Line("Please enter your address");
   Get(strAddress, length_In2);
....

The problem is that after I put the integer in and push enter
(in response to the first question)  the next line is outputted
(Please enter your name) but then before I could enter the name, the
prompt for address is outputted, the get(strName..) is completely
skipped.  I have tried several things and can't get this to work. 
What am I doing wrong?? I'm thinking that the problem might be with
the get option, such that it is grabbing too many characters, b/c when
that line is commented out and i hardcord in the option number
everything works as it should. The problem is not w/ the New_Line
after the Get(strName...) I have tried playing around w/ this, its
omission makes no difference.


Example of output....
Please enter an option
3
Please enter your name        --wrong! i did not get to input the
name!!!
Please enter your address



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Newbie question: input problem
@ 2002-04-10  5:37 Christoph Grein
  0 siblings, 0 replies; 3+ messages in thread
From: Christoph Grein @ 2002-04-10  5:37 UTC (permalink / raw)


This is a pitfall virtually any newcomer falls into...

Get(Option, 1) does not consume too many characters, it consumes less than you 
think - it does not consume the EoL (the character issued when you push enter), 
in fact is consumes just one character, as specified by the second argument 1.
So an empty input line is present for Get(strName, length_In) [which I assume in 
your proper program is Get_Line, there is no such Get in Ada.Text_IO], or, if 
you happen to input more than one digit, the rest of the digits.

Just try the following:
> Please enter an option
> 32
Your name will most probably hold the value 2.

So what is missing is a Skip_Line after Get(Option, 1).

Please have a look at RM A.10.

A further hint: Use named associations for plain numbers, e.g.
Get(Option, Width => 1)
This will make you program much more readable.

> From: sidney_bhaiji@hotmail.com
> 
> Hi, 
>    I have the following problem...
> Consider the following lines of code....
> 
> Option: Integer;
> strName, strAddress: String(1..50);
> length_In, length_In2: Integer;
> 
> Put_Line("Please enter an integer according to what you want to do");
> Get(Option, 1);New_Line;
> 
> if (Option = 3) then
>    Put_Line("Please enter your name");
>    Get(strName, length_In); New_Line;
>    Put_Line("Please enter your address");
>    Get(strAddress, length_In2);
> ....
> 
> The problem is that after I put the integer in and push enter
> (in response to the first question)  the next line is outputted
> (Please enter your name) but then before I could enter the name, the
> prompt for address is outputted, the get(strName..) is completely
> skipped.  I have tried several things and can't get this to work. 
> What am I doing wrong?? I'm thinking that the problem might be with
> the get option, such that it is grabbing too many characters, b/c when
> that line is commented out and i hardcord in the option number
> everything works as it should. The problem is not w/ the New_Line
> after the Get(strName...) I have tried playing around w/ this, its
> omission makes no difference.
> 
> 
> Example of output....
> Please enter an option
> 3
> Please enter your name        --wrong! i did not get to input the
> name!!!
> Please enter your address
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada.eu.org
> http://ada.eu.org/mailman/listinfo/comp.lang.ada



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Newbie question: input problem
  2002-04-10  2:13 Newbie question: input problem Sidney Bhaiji
@ 2002-04-10  8:22 ` John McCabe
  0 siblings, 0 replies; 3+ messages in thread
From: John McCabe @ 2002-04-10  8:22 UTC (permalink / raw)


On 9 Apr 2002 19:13:13 -0700, sidney_bhaiji@hotmail.com (Sidney
Bhaiji) wrote:

>Option: Integer;
>strName, strAddress: String(1..50);
>length_In, length_In2: Integer;
>
>Put_Line("Please enter an integer according to what you want to do");
>Get(Option, 1);New_Line;
>
>if (Option = 3) then
>   Put_Line("Please enter your name");
>   Get(strName, length_In); New_Line;
>   Put_Line("Please enter your address");
>   Get(strAddress, length_In2);

Instead of "New_Line" use "Skip_Line". New_Line is an output method.




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2002-04-10  8:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-04-10  2:13 Newbie question: input problem Sidney Bhaiji
2002-04-10  8:22 ` John McCabe
  -- strict thread matches above, loose matches on Subject: below --
2002-04-10  5:37 Christoph Grein

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox