Question from newbie

From: Cecilia Chew (cecilia_at_nowhere.com)
Date: 02/16/04


Date: Mon, 16 Feb 2004 10:43:36 +0800

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:
========================================================================
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
       Left : Character;
       Right : Character;
       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);
    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 num in Index loop
          Get (Input (Num));
          if Input'Length = num then

             for I in 1 .. num loop
               Ascending_char (Input(i), Input(i+1));
             end loop;
        
            while not End_Of_Line loop
               Put (Input(Num));
            end loop;
        
        else
            exit;
        end if;
        
       end loop;
end if;
end Sort;
=============================================================================
Question:
1. As the procedure ascending compiles as a independent unit with the
     other file name, it could sort the two characters correctly.
     However, as I put it together with sort.adb program. Specification
     part that declared the procedure ascending conflict with the
     variable left and right. Where is the mistake?

2. Before plug in the procedure ascending, the program successfully
     being compiled. But the program can't allocate the specified space
     as x characters in outputting the result. For an example, user
     specified 2 characters, but the program still allow user to input
     less than or excess 2 characters..Where is the mistakes?

3. From my coding, what should I pay more attention to?

Please kindly give me any comments..

Regards,

--
Cecilia
-- 
Cecilia Chew
c e c i l i a <AT> g r e e n l i m e . c o m