comp.lang.ada
 help / color / mirror / Atom feed
From: "Keith C. McCready" <kmccready@agweb.com>
Subject: Newbie:  Ada function like C++'s atoi?
Date: 2000/03/28
Date: 2000-03-28T00:00:00+00:00	[thread overview]
Message-ID: <38e17eab@news.siscom.net> (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







             reply	other threads:[~2000-03-28  0:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-03-28  0:00 Keith C. McCready [this message]
2000-03-28  0:00 ` Newbie: Ada function like C++'s atoi? Vincent Marciante
2000-03-29  0:00 ` Robert Dewar
replies disabled

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