| | |
Please help me on Delphi.
Please support our Pascal and Delphi advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
delphi Syntax (Toggle Plain Text)
procedure TForm1.Button1Click(Sender: TObject); Var i1, iResult: Integer; begin iResult := 0; for i1 := 2 to 20 do begin if ((i1 mod 2) = 0) then Inc(iResult, i1); end; ShowMessage(IntToStr(iResult)); end;
Hi Turbomen 
If you want to create a console application then this is also a solution

If you want to create a console application then this is also a solution
delphi Syntax (Toggle Plain Text)
Program EvenOrNot; {$APPTYPE CONSOLE} Uses SysUtils; Var i,counter:LongInt; TheOdds:Boolean; {true or false} Begin i:=2; counter:=0; Write('The even numbers are: '); While i<=21 Do Begin TheOdds:=Odd(i); If (TheOdds=False) Then Begin Write(i,' '); counter:=counter+i;{increase *counter* by *i*} End;{of if} Inc(i,1); {increase *i* by 1} End;{of while} WriteLn; {put the cursor to the home of the next line} Write('Total : ',counter); ReadLn; {press enter to quit} End. {of main} { -=Notes=- ODD FUNCTION:Tests if the argument is an odd number. DECLARATION: ODD(X:LONGINT):BOOLEAN; THE ODD FUNCTION RETURNS *TRUE* IF *X* IS AN ODD NUMBER -=End Of Notes=- Created By FlamingClaw 2009.07.12 }
Last edited by FlamingClaw; Jul 12th, 2009 at 3:19 pm.
Be a good part of the community.Don't be ungrateful.
If you ask something on the forum and you got the right answer then mark as solved!
If my opinion helped to you a lot then sometimes give reputation point to me.
I'm just a pascal programmer from Hungary.
Farewell...
If you ask something on the forum and you got the right answer then mark as solved!
If my opinion helped to you a lot then sometimes give reputation point to me.
I'm just a pascal programmer from Hungary.
Farewell...
Hi Turbomen 
We store the sum of the even numbers in the variable named *Counter*.
When the program is running first *Counter* 's value is zero.
Counter:=0;
*TheOdds* variable is holds a *true* or *false* value changed by the built in function Odd(i) that wait longint and send back boolean,true if *i* is odd and false if *i* is even number
If *TheOdds* is false then *i* is an even number,so the *Counter*'s value will increase by *i*
Counter:=Counter+i;
Else *Counter* stays unchanged

We store the sum of the even numbers in the variable named *Counter*.
When the program is running first *Counter* 's value is zero.
Counter:=0;
*TheOdds* variable is holds a *true* or *false* value changed by the built in function Odd(i) that wait longint and send back boolean,true if *i* is odd and false if *i* is even number
If *TheOdds* is false then *i* is an even number,so the *Counter*'s value will increase by *i*
Counter:=Counter+i;
Else *Counter* stays unchanged
Be a good part of the community.Don't be ungrateful.
If you ask something on the forum and you got the right answer then mark as solved!
If my opinion helped to you a lot then sometimes give reputation point to me.
I'm just a pascal programmer from Hungary.
Farewell...
If you ask something on the forum and you got the right answer then mark as solved!
If my opinion helped to you a lot then sometimes give reputation point to me.
I'm just a pascal programmer from Hungary.
Farewell...
![]() |
Similar Threads
- How to use bluetooth libs with Delphi 7 (Pascal and Delphi)
- Looking for a Senior DELPHI Developer (Software Development Job Offers)
- Delphi Onjects (Pascal and Delphi)
- Cscgal wouldja add a Delphi forum here? (IT Professionals' Lounge)
Other Threads in the Pascal and Delphi Forum
- Previous Thread: find replace
- Next Thread: How to smaller my attach image to Database?
| Thread Tools | Search this Thread |






