comp.lang.ada
 help / color / mirror / Atom feed
* Newbie:  Ada function like C++'s atoi?
@ 2000-03-28  0:00 Keith C. McCready
  2000-03-28  0:00 ` Vincent Marciante
  2000-03-29  0:00 ` Robert Dewar
  0 siblings, 2 replies; 3+ messages in thread
From: Keith C. McCready @ 2000-03-28  0:00 UTC (permalink / raw)


Greetings,

I am a college student taking an introductory Ada programming class who is
familiar with C/C++.  Looking for Ada function similar to atoi.  Purpose: I
want the following to raise an exception when the user enters a floating
point value.  Right now, if the user enters a value of 3.1415, the value
received by the Get is 3.

I would like to read the user input as a character string, convert and
validate that the string is an integer value within the range of
Percent_Type.

*************************
-- subtypes
subtype Percent_Type is Integer range 0..100;

-- variables:
Percent    : Percent_Type;

-- procedures:
procedure Check_Percent ( Percent  : out Percent_Type ) is

begin -- Check_Percent
    Validation_Loop:
      loop

        Percent_Validation_Block:
        begin
            Integer_IO.Get ( Item => Percent );
            exit Validation_Loop;

            exception
                 when CONSTRAINT_ERROR =>
                      Text_IO.Put ( Item => "Valid range is 0 to 100" );
                      Text_IO.New_Line;
                      Text_IO.Skip_Line;

                 when others =>
                      Text_IO.Put ( Item => "Enter an integer value of 0 to
100:  " );
                      Text_IO.New_Line;
                      Text_IO.Skip_Line;
       end Percent_Validation_Block;

  end loop Validation_Loop;

end Check_Percent;

******************

Thanks for any suggestions or comments,

Keith C. McCready

mccreak9708@uni.edu

kmccready@agweb.com







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

end of thread, other threads:[~2000-03-29  0:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-03-28  0:00 Newbie: Ada function like C++'s atoi? Keith C. McCready
2000-03-28  0:00 ` Vincent Marciante
2000-03-29  0:00 ` Robert Dewar

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