Reputation: 49
I want to see if the numbers in an array are factors of 50 or not
I created an array of integers and tried to determine using mod , but can't seem to get it right
//Global
var
Form1: TForm1;
Num: array [1 .. 100] of integer;
ask: integer;
i, j, temp: integer;
procedure TForm1.btnDisplayCriteriaClick(Sender: TObject);
var
temp, fac :integer;
begin
fac:=num[ask];
if rbgCriteria.ItemIndex=0 then
begin
for I := 1 to ask do
begin
if fac mod 50=0 then
fac:=num[i];
Inc(fac);
end;
redDisplay.Lines.Add(IntToStr(fac)+' is a factor of 50')
end;
end;
I expect it to show whether number() is a factor of 50 but instead I get the position
Upvotes: 0
Views: 380
Reputation: 2416
It is correct for the procedure to return the position, judging by how you wrote the code. This is because fac
stores the position of the array's element you work with (the array being Num
). So, you're testing if the position you're working with divides 50, not the actual number.
procedure TForm1.btnDisplayCriteriaClick(Sender: TObject);
var
i :integer;
begin
if rbgCriteria.ItemIndex=0 then
for I := 1 to ask do
if (num[i] mod 50) = 0 then
redDisplay.Lines.Add(IntToStr(num[i])+' is a factor of 50')
end;
Upvotes: 2