comp.lang.ada
 help / color / mirror / Atom feed
From: "isaac2004" <isaac_2004@yahoo.com>
Subject: Re: creating an array
Date: 14 Feb 2006 13:14:24 -0800
Date: 2006-02-14T13:14:24-08:00	[thread overview]
Message-ID: <1139951664.264622.240870@z14g2000cwz.googlegroups.com> (raw)
In-Reply-To: <ldbke401hna0.1ctkkgjler8xb.dlg@40tude.net>

ok to everybody trying to help me thank you i didnt specify enough. i
have a program that takes two inputs from prompts, the first number is
an integer less than 10. the second number has the amount of digits
that the previous number specifies. what i want to do is split the
number up into single digits, sort them and out put the min ascending
order.

here is my code i cant get the split function right

with Ada.Text_Io;
use Ada.Text_Io;
with Ada.Integer_Text_Io;
use Ada.Integer_Text_Io;
procedure test is

-----------------------------------------------------------------------------------------------
   --| Recieves two inputs, one being a number les than ten and the
other number is a number with the same amount of digits
   --| as the first recieved number. the second number is then
seperated, the digits stored in an array and put into ascending order
   --| Author: Isaac Levin, Western Washington University
   --| Last Modified: February 2006

----------------------------------------------------------------------------

   type Index is Natural range 1 .. 10
   type Number is Natural range 000000000 .. 999999999;
   type Positivearray is array (Index) of Positive;

   Num1      : Number;
   Num_Array : Positivearray;
   Prompt    : Index;
   Numdigit  : Number;

   procedure Split (
         N1 : in     Number;
         A  : in out Positivearray ) is
      Temp : Integer := 1;
      Remain    : Number;
   begin
      for I in 1..(Prompt - 1) loop
         Temp := Temp * 10;
      end loop;
      for I in Positivearray'range loop
         A(N1) := Temp rem 10;
         Remain := Remain rem Temp;
         Temp := Temp / 10;
         if Num1(N1) /= 0 then
            N1 := N1 + 1;
         end if;
      end loop;
   end Split;

   procedure Sort (
         Thearray : in out Positivearray;
         Inuse    : in     Natural        ) is
      -- Sorts the elements of the array from smallest to largest
      Min      : Positive;
      Indexmin : Positive;
      Temp     : Positive;
   begin

      for I in 1..Inuse - 1 loop
         Min := Thearray(I);
         Indexmin := I;
         for J in I + 1 .. Inuse loop
            if Thearray(J) < Min then
               Min := Thearray(J);
               Indexmin := J;
            end if;
         end loop;
         Temp := Thearray(I);
         Thearray(I) := Min;
         Thearray(Indexmin) := Temp;
      end loop;
   end Sort;

   -- end of ascending procedure



begin
   Put(Item => " Please enter a number with ");
   Put(Item => Prompt);
   Put(Item => " or fewer digits: ");
   New_Line;
   Get(Item => Num1);
   New_Line;

   Split (Num1, Prompt);
   Sort (Num1, Prompt);
   New_Line;
   Put ("The numbers in sorted order are");
   New_Line;
   for I in 1..Prompt loop
      Put (Num1(I), 0);
      New_Line;
   end loop;

end test;

any help would be greatly appreciated




  reply	other threads:[~2006-02-14 21:14 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 [this message]
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
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