comp.lang.ada
 help / color / mirror / Atom feed
* Question from newbie
@ 2004-02-16  2:43 Cecilia Chew
  2004-02-16 10:49 ` Luke Guest
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Cecilia Chew @ 2004-02-16  2:43 UTC (permalink / raw)


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



^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2004-02-18 10:24 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

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