•

Check out our Community Blogs

Register and join over 40,000 other developers!

### Recent Blog Entries

• phi

I love this community !

• JackJames

hi i am jack i am seo expert jack james would love you to read new post

# Dividing

delphi

2 replies to this topic

### #1 Sparky

Sparky

CC Newcomer

• Just Joined
• 10 posts

Posted 23 September 2008 - 04:24 AM

Hi im new at this forum.
I've been donig delphi for almost a year now, but i still have problems in my programs as i am not a professional. My latest problem is that i have to created a program that divides two random numbers. The problem is that the answer must be a whole number and not a decimal one. THe second number must also divide exactely in to the first one.
For example: 10 / 5 = 2 and not 10 / 3 = 3.333333
The first number has also got to be greater than the second number.

This is my code and it exicutes it when a button is pressed, it is incomplete, but my main aim is to get the answer as above.
```procedure divide;
begin
Randomize;
end ;

procedure TfrmPrimary.BitBtnDivideClick(Sender: TObject);
var
begin
Randomize;
if not (rResult In [1..20]) then
divide;
If StrToInt(Inputstr) = iResult then
inc(iRight,1) else
inc(iWrong,1);
If StrToInt(Inputstr) = iResult then
lblRightDivide.Caption := 'Number of Correct Answers: ' + IntToStr(iRight)  else
lblWrongDivide.Caption := 'Number of Incorrect Answers: ' + IntToStr(iWrong);
end;

```
Thanks

Edited by WingedPanther, 23 September 2008 - 09:09 AM.

• 0

### #2 WingedPanther73

WingedPanther73

A spammer's worst nightmare

• Moderator
• 17757 posts
• Location:Upstate, South Carolina
• Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
• Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 23 September 2008 - 09:11 AM

It looks like you may be approaching this backwards. To get two numbers that divide evenly, instead find to random numbers and multiply them, use one number and the product as your "random numbers". Also, use round/trunc to convert to an integer and store the result in an integer.
• 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/

### #3 Sparky

Sparky

CC Newcomer

• Just Joined
• 10 posts

Posted 24 September 2008 - 08:38 AM

Thanks it works well
• 0

### Also tagged with one or more of these keywords: delphi

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download