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-7-bit X-Google-Thread: 103376,866f55656f224cc8 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2004-02-18 02:02:01 PST Date: Wed, 18 Feb 2004 17:52:40 +0800 From: Cecilia Chew User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6b) Gecko/20031205 Thunderbird/0.4 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Question from newbie References: <40302ec4$1_2@news.tm.net.my> In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 219.95.190.199 X-Original-NNTP-Posting-Host: 219.95.190.199 Message-ID: <4033365e_1@news.tm.net.my> X-Trace: news.tm.net.my 1077098078 219.95.190.199 (18 Feb 2004 17:54:38 +0800) Organization: TMnet Malaysia Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!nntp.abs.net!ash.uu.net!news1.tm.net.my Xref: archiver1.google.com comp.lang.ada:5643 Date: 2004-02-18T17:52:40+08:00 List-Id: Hi all, I'm an Ada learner and under a supervisor. This is one of my task during learning period. From group comments that had provided, I did some amendments but the program still have errors. I wonder what to do. Below is after amendments program : =========================================================================== 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 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)); for Character_Number in 1 .. num loop Ascending (Left => Input(Character_Number), Right => Input(Character_Number + 1)); Input(Num) := Input (Character_Number); end loop; Put (Input (Num)); end loop; end if; end Sort; =============================================================================== 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? By the way, thanks the comments from Luke Guest, Jacob Sparre Andersen and Preben Randhol. Preben Randhol wrote: > On 2004-02-16, Cecilia Chew wrote: > >>Hi all, >>I'm still in learning Ada. However, there were something missing in >>coding. Could someone point out my problems. Just take an example, i'm >>now doing a program that ask user input x characters and program will >>sort the user's input into ascending order. The is below: > > > Before helping two questions: > > 1. Is this homework? > 2. Why do you do this: type Str is array (Index) of Char; > > > > -- Cecilia Chew c e c i l i a g r e e n l i m e . c o m