From: Cecilia Chew <cecilia@nowhere.com>
Subject: Re: Question from newbie
Date: Wed, 18 Feb 2004 17:52:40 +0800
Date: 2004-02-18T17:52:40+08:00 [thread overview]
Message-ID: <4033365e_1@news.tm.net.my> (raw)
In-Reply-To: <slrnc3188p.3ja.randhol+valid_for_reply_from_news@k-083152.nt.ntnu.no>
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 <cecilia@nowhere.com> 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 <AT> g r e e n l i m e . c o m
next prev parent reply other threads:[~2004-02-18 9:52 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-02-16 2:43 Question from newbie Cecilia Chew
2004-02-16 10:49 ` Luke Guest
2004-02-16 10:53 ` Preben Randhol
2004-02-16 15:46 ` Jacob Sparre Andersen
2004-02-16 16:14 ` Preben Randhol
2004-02-18 9:52 ` Cecilia Chew [this message]
2004-02-18 10:19 ` Jacob Sparre Andersen
2004-02-18 10:24 ` Adrian Hoe
2004-02-18 10:24 ` Adrian Hoe
2004-02-18 10:21 ` Adrian Hoe
2004-02-16 11:20 ` Jacob Sparre Andersen
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox