From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII X-Google-Thread: 103376,866f55656f224cc8 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2004-02-18 02:19:31 PST Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.freenet.de!news.shlink.de!news2.telebyte.nl!news.jgaa.com!news.hacking.dk!pnx.dk!munin.nbi.dk!not-for-mail From: Jacob Sparre Andersen Newsgroups: comp.lang.ada Subject: Re: Question from newbie Date: 18 Feb 2004 11:19:29 +0100 Organization: Munin Sender: sparre@sparre.crs4.it Message-ID: References: <40302ec4$1_2@news.tm.net.my> <4033365e_1@news.tm.net.my> NNTP-Posting-Host: sparre.crs4.it Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: munin.grove.home 1077099570 15243 156.148.70.170 (18 Feb 2004 10:19:30 GMT) X-Complaints-To: sparre@munin.nbi.dk NNTP-Posting-Date: Wed, 18 Feb 2004 10:19:30 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Xref: archiver1.google.com comp.lang.ada:5644 Date: 2004-02-18T11:19:29+01:00 List-Id: Cecilia Chew wrote: > with Ada.Text_Io, Ada.Integer_Text_Io; > use Ada.Text_Io, Ada.Integer_Text_io; > > procedure Sort is > subtype Index is Integer range 1 .. 10; > subtype Char is Character range 'a' .. 'z'; > type Str is array (Index) of Char; > procedure Ascending (Left : in out Character; Right : in out > Character); > > procedure Ascending (Left : in out Character; Right : in out > Character) is > > Temp : Character; > begin > if Left > Right then > Temp := Left; > Left := Right; > Right := Temp; > end if; > end Ascending; > > Num : Index; > Input : Str; > > begin > Put ("Please enter the number of character : "); > Get (Num); > Ada.Text_Io.Skip_Line; > New_Line; > if Num not in Index then This check should not be necessary. Since "Num" is of the subtype "Index", it _can_ only have values that are in "Index". You should on the other hand get a "Constraint_Error", if you try to enter a number that is not in the range of "Index". > Put ("Please enter 1 to 10 characters only!"); > else > Put ("Please enter" & Integer'Image(Num) & " characters : "); > for Character_number in Index'First .. Num loop > Get (Input(Character_number)); [ here's line 36 - I think ] Did you actually enter "Num" characters in the range 'a' .. 'z'? A "Constraint_Error" indicates that something is out of range. It can't be "Character_Number", since both "Index'First" and "Num" are valid values of the subtype "Index" (and "Character_Number" thus always will be a valid index for the array "Input"). The alternative is that the character you entered wasn't in the valid range for "Input (Character_Number)", i.e. in the range 'a' .. 'z'. > This program could get user input characters but not the specified x > character and any range of characters will occurred error as below. > > raised CONSTRAINT_ERROR : sort.adb:36 range check failed > > where is the problem? Jacob -- �When Roman engineers built a bridge, they had to stand under it while the first legion marched across. If programmers today worked under similar ground rules, they might well find themselves getting much more interested in Ada!� -- Robert Dewar