Delphi Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreDelphi Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 4th, 2005, 05:17 AM
n00n n00n is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 1 n00n User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 30 sec
Reputation Power: 0
Please explain what this does?

My teacher gave us this code to analise and we are supposed to report back and tell him what each section does, but I have no clue what is happening. We are still doing loops and if then else statements in our syllabus, so I am new to all of this.

What this program does is take a 4 digit number, re-arrange it to 2 new numbers biggest to smallest and smallest to biggest (eg 3765 = 7653 and 3567) subtracts them from each other and does it again until it equals 6174, then displays all the results in a memo box.

heres the code:
Code:
var num1,num2,num3,num4,whole,hi,lo,x,hold,count : integer;
    wholes,num1s,num2s,num3s,num4s,His,Los,pali:string;
begin
wholes:=edit1.text;
listbox1.Clear;
count:=0;

for x:=1 to 4 do
insert(copy(wholes,1,1),pali,1);

if ((strtoint(edit1.Text) > 1000) and (strtoint(edit1.Text) < 9998)) and ((wholes <> pali)) then
repeat
count:=count+1;


insert(copy(wholes,1,1),num1s,1);
insert(copy(wholes,2,1),num2s,1);
insert(copy(wholes,3,1),num3s,1);
insert(copy(wholes,4,1),num4s,1);

num1:=strtoint(num1s);
num2:=strtoint(num2s);
num3:=strtoint(num3s);
num4:=strtoint(num4s);

for x:=0 to 6 do
begin
        if num1<num2 then
        begin
        hold:=num1;
        num1:=num2;
        num2:=hold;
        end;

        if num2<num3 then
        begin
        hold:=num2;
        num2:=num3;
        num3:=hold;
        end;

        if num3<num4 then
        begin
        hold:=num3;
        num3:=num4;
        num4:=hold;
        end;
end;

num1s:=inttostr(num1);
num2s:=inttostr(num2);
num3s:=inttostr(num3);
num4s:=inttostr(num4);
his:=num1s+num2s+num3s+num4s;
los:=num4s+num3s+num2s+num1s;

hi:=strtoInt(his);
lo:=strtoInt(los);
whole:=hi-lo;
wholes:=inttostr(whole);
listbox1.Items.Add(inttostr(count)+': '+his+' - '+los+' = '+wholes);

//showmessage(his+' - '+los+' = '+wholes);
num1s:='';
num2s:='';
num3s:='';
num4s:='';
until whole=6174
else
showmessage('Please try again, the number you typed in cannot be less than 1001 and the values cannot be al the same. eg 1111 or 2222');
end;

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreDelphi Programming > Please explain what this does?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT