comp.lang.ada
 help / color / mirror / Atom feed
* Newbie question on Ada TExt_IO
@ 2002-10-03 18:20 Justin
  2002-10-03 18:50 ` Matthew Heaney
                   ` (6 more replies)
  0 siblings, 7 replies; 27+ messages in thread
From: Justin @ 2002-10-03 18:20 UTC (permalink / raw)


Hi,

I'm relatively new to Ada.  I've read 1/2 of Programming in Ada95 by
Barnes, done half of Lovelace and read as much as I can stomach of the
Ada RM. Forgive me if this question is too basic, but I've been unable
to see any reference to it in the previous documentation.

I'm doing TextIO from the command prompt.  But I'm having difficulty
validating the input.  For example I'm asking the user to enter a
number, let's say I'm expecting an integer between 1 and 6

X:Integer;
...
Put("Please enter a number between 1 and 6);
Get(x);

But what if they give me 'abc' or 4.44 or simply
1230000000000000000000000000000000000000000000000000000000000000000000000

How can I handle this?  From my take on what I've read I should avoid
exception handling for things I'm not expecting, so I've ruled out
exceptions, that leaves me with obtaining a value of generic type and
evalutating the type at run-time...how can I do this?  Is this the
right strategy?

Thanks for they help,
Justin



^ permalink raw reply	[flat|nested] 27+ messages in thread
* Re: Newbie question on Ada TExt_IO
@ 2002-10-07  6:01 Grein, Christoph
  0 siblings, 0 replies; 27+ messages in thread
From: Grein, Christoph @ 2002-10-07  6:01 UTC (permalink / raw)


when you test your program, try the following inputs (non-exhaustive list)

<Return>
1<Return>
 1<Return>
01<Return>
16<Return>
1 1<Return>
1a<Return>
1 a<Return>
a<Return>
 a<Return>

It's upon you to decide which of the above are valid. Also note that Ada syntax 
for integers includes exponential form: 1E+0 is a valid input for 1.



^ permalink raw reply	[flat|nested] 27+ messages in thread
* Re: Newbie question on Ada TExt_IO
@ 2002-10-07  8:27 Grein, Christoph
  2002-10-07 11:48 ` Fraser Wilson
  0 siblings, 1 reply; 27+ messages in thread
From: Grein, Christoph @ 2002-10-07  8:27 UTC (permalink / raw)


> > subtype Valid_Number is Integer range 1 .. 6;
> > N : Valid_Number;
> > ...
> > N := Integer'Value (Input (Input'First .. Last) );
> 
> Should this be
> 
> N := Valid_Number'Value (Input (Input'First .. Last));
> 
> ?
> 
> (Pedantor is in the building)

Attributes can use as prefix either the subtype or the type (which in fact is 

is the first named subtype) without difference.



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

end of thread, other threads:[~2002-10-07 19:44 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-03 18:20 Newbie question on Ada TExt_IO Justin
2002-10-03 18:50 ` Matthew Heaney
2002-10-03 19:05 ` Jeffrey Carter
2002-10-03 19:35 ` David C. Hoos
2002-10-03 19:35 ` tmoran
2002-10-03 19:43 ` Preben Randhol
2002-10-03 19:55   ` Matthew Heaney
2002-10-03 20:07     ` Preben Randhol
2002-10-04  2:42 ` SteveD
2002-10-04 17:49   ` Justin Birtwell
2002-10-04 18:00     ` David C. Hoos
2002-10-04 18:04       ` Preben Randhol
2002-10-04 18:00     ` Preben Randhol
2002-10-04 18:02       ` Preben Randhol
2002-10-04 18:34     ` tmoran
2002-10-04 17:34 ` Justin Birtwell
2002-10-04 17:58   ` Preben Randhol
2002-10-04 18:13   ` tmoran
2002-10-04 20:07   ` Jeffrey Carter
2002-10-07  8:26     ` Fraser Wilson
2002-10-07 19:44       ` Jeffrey Carter
2002-10-05  2:43   ` SteveD
2002-10-05  5:25     ` tmoran
  -- strict thread matches above, loose matches on Subject: below --
2002-10-07  6:01 Grein, Christoph
2002-10-07  8:27 Grein, Christoph
2002-10-07 11:48 ` Fraser Wilson
2002-10-07 12:46   ` Robert A Duff

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