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; var iAdd1, iAdd2, iresult : integer; begin Randomize; iAdd1 := Random(20) + 1; iAdd2 := Random(20) + 1; iResult := iAdd1 div iAdd2; end ; procedure TfrmPrimary.BitBtnDivideClick(Sender: TObject); var rAdd1, rAdd2, ireal, rResult : Real; begin Randomize; rAdd1 := Random(20) + 1; rAdd2 := Random(20) + 1; rResult := rAdd1 / rAdd2; if not (rResult In [1..20]) then divide; Inputstr := InputBox('Addition [ / ]', IntToStr(iAdd1) + '/' + IntToStr(iAdd2) + ' - Always put in a Answer','0'); 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;The code my look a mess, but could anyone please help
Edited by WingedPanther, 23 September 2008 - 09:09 AM.
add code tags