comp.lang.ada
 help / color / mirror / Atom feed
From: "jimmaureenrogers@worldnet.att.net" <jimmaureenrogers@worldnet.att.net>
Subject: Re: creating an array
Date: 15 Feb 2006 19:09:07 -0800
Date: 2006-02-15T19:09:07-08:00	[thread overview]
Message-ID: <1140059347.793793.135880@g44g2000cwa.googlegroups.com> (raw)
In-Reply-To: 1140046148.803154.70980@f14g2000cwb.googlegroups.com

Now that you have a complete program, here is the solution I was
thinking of.

with Ada.Text_Io;

procedure Sort_Digits is
   procedure Sort_Characters (Buffer : in out String) is
      Exchanged : Boolean;
      Temp : Character;
   begin
      loop
         Exchanged := False;
         for I in Buffer'First..Buffer'Last - 1 loop
            if Buffer(I) > Buffer(I + 1) then
               Temp := Buffer(I + 1);
               Buffer(I + 1) := Buffer(I);
               Buffer(I) := Temp;
               Exchanged := True;
            end if;
         end loop;
         exit when not Exchanged;
      end loop;
   end Sort_Characters;
   Input_String : String(1..10);
   Length       : Natural;
begin
   Ada.Text_Io.Put_Line("Enter a number of no more than 10 digits");
   Ada.Text_Io.Get_Line(Item => Input_String, Last => Length);
   Sort_Characters(Input_String(1..Length));
   Ada.Text_Io.Put_Line(Input_String(1..Length));
end Sort_Digits;


Note that there is only one input, the number to be sorted.
The resulting output matches your program requirements.
There can never be a mis-match between stated and actual sizes
of the input string. There is no need to raise an exception due to
parameter inconsistencies.

Jim Rogers




  reply	other threads:[~2006-02-16  3:09 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-02-14  6:06 creating an array isaac2004
2006-02-14 13:59 ` jimmaureenrogers
2006-02-14 15:20   ` isaac2004
2006-02-14 18:44     ` jimmaureenrogers
2006-02-14 19:25 ` Björn Persson
2006-02-14 19:39   ` Dmitry A. Kazakov
2006-02-14 21:14     ` isaac2004
2006-02-14 22:17       ` jimmaureenrogers
2006-02-14 22:30         ` isaac2004
2006-02-14 22:45         ` Ludovic Brenta
2006-02-14 22:54           ` isaac2004
2006-02-14 23:10             ` Ludovic Brenta
2006-02-14 23:37               ` isaac2004
2006-02-15  7:45                 ` Anders Wirzenius
2006-02-15 20:44                   ` Björn Persson
2006-02-16  6:59                     ` Anders Wirzenius
2006-02-15 21:53                 ` Ludovic Brenta
2006-02-15 23:29                   ` isaac2004
2006-02-16  3:09                     ` jimmaureenrogers [this message]
2006-02-15  7:42     ` Maciej Sobczak
2006-02-15 10:37       ` Jean-Pierre Rosen
2006-02-15 13:30       ` Dmitry A. Kazakov
2006-02-15 16:23         ` isaac2004
replies disabled

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