From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,3323ee59cb66d2b6,start X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!g14g2000cwa.googlegroups.com!not-for-mail From: "isaac2004" Newsgroups: comp.lang.ada Subject: do while loop help ( newbie) Date: 4 Feb 2006 15:16:19 -0800 Organization: http://groups.google.com Message-ID: <1139094979.043765.42770@g14g2000cwa.googlegroups.com> NNTP-Posting-Host: 67.170.5.168 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1139094984 23897 127.0.0.1 (4 Feb 2006 23:16:24 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sat, 4 Feb 2006 23:16:24 +0000 (UTC) User-Agent: G2/0.2 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727),gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: g14g2000cwa.googlegroups.com; posting-host=67.170.5.168; posting-account=bWy1LAwAAAAtVkasDCH0ykMCBMNd-FcL Xref: g2news1.google.com comp.lang.ada:2777 Date: 2006-02-04T15:16:19-08:00 List-Id: hi im new to ada and im having trouble with executing a do while loop. im trying to take an input number called Number and sort it into ascending and descending order and subtract the two to get a new number called NewNumber. i want the loop to continue looping until variable Number is equal to variable NewNumber. if this doesnt make sense here is my code with Ada.Text_IO; use Ada.Text_IO; with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; procedure Assignment2 is ----------------------------------------------------------------------------------------------- --| Recieves four variables and uses Kaprekar's Function to arrange them into descending order and --| and subtract the number in ascending order from it --| Author: Isaac Levin, --| Last Modified: January 2006 ---------------------------------------------------------------------------- subtype Digit is Natural range 0 .. 9; D1 : Digit; -- a list of four single digit numbers D2 : Digit; D3 : Digit; D4 : Digit; Number : Natural range 0 .. 9999; -- number taken from user Temp : Natural; AsNumber : Natural; -- number in ascending order DsNumber : Natural; -- number in descening order NewNumber : Natural; -- new number derived from DsNumber - AsNumber -- procedure specifications procedure Order ( X : in out Natural; Y : in out Natural); -- procedure body procedure Order ( X : in out Natural; Y : in out Natural) is -- pre: X and Y are assigned values; -- post: X has the smaller value and Y has the larger value Temp : Natural; --copy of number originally in X begin -- Order if X > Y then Temp := X ; -- store X into temp X := Y ; -- move old y into x Y := Temp ; -- move old x from temp to y end if; end Order; begin loop begin -- block for exception handler Put(Item => "Please enter a four digit number."); New_Line; Get(Item => Number); exit; exception when Constraint_Error => Put ("The input value or result is out of range."); Skip_Line; New_Line; when Data_Error => Put (Item => "The input value is not well formed."); Skip_Line; New_Line; end; -- block for exception handler end loop; while Number /= NewNumber loop -- extract digits of number Temp := Number ; D1:= Temp rem 10 ; Temp := Temp / 10 ; D2:= Temp REM 10; Temp:= Temp / 10; D3:= Temp REM 10; Temp := Temp / 10; D4 := Temp REM 10; -- sort the digits of the number Order ( X => D1, Y => D2); Order ( X => D1, Y => D3); Order ( X => D1, Y => D4); Order ( X => D2, Y => D3); Order ( X => D2, Y => D4); Order ( X => D3, Y => D4); -- put ascending and descending digits back into numbers AsNumber := (D1 * 1000) + (D2 * 100) + (D3 * 10) + D4; DsNumber := (D4 * 1000) + (D3 * 100) + (D2 * 10) + D1; -- subtract ascending number from descending number NewNumber := DsNumber - AsNumber; -- display the results Put( Item => Dsnumber, Width => 1); Put(Item => " - "); Put( Item => Asnumber, Width => 1); Put(Item => " = "); Put( Item => Newnumber, Width => 1); Number := NewNumber; end loop ; end Assignment2; it looks right to me but it just will not start the loop any help would be great. thanx before hand