procedure TForm1.Button1Click(Sender: TObject);
label 1;
var
a,b,k,ans:integer;
tt:array[1..12] of integer;
errors1:boolean;
calcstr2,calcstr1,calcstr3:string[30];
begin
Canvas.Font.Style:=[fsbold];
Canvas.Font.Size:=14;
errors1:=false;
form1.hide;
form1.show;
try
a:=strtoint(form1.edit1.Text);
except
errors1:=true;
end;
if (errors1=true) or
(a<1) or (a>12)
then begin
form1.canvas.textout(0,100,'CHECK ENTRIES.');
goto 1
end;
randomize;
for k:=1 to 12 do
tt[k]:=0;
tt[1]:=random(12)+1;
repeat
tt[2]:=random(12)+1
until (tt[2]<>tt[1]);
repeat
tt[3]:=random(12)+1
until (tt[3]<>tt[1]) and (tt[3]<>tt[2]);
repeat
tt[4]:=random(12)+1
until (tt[4]<>tt[1]) and (tt[4]<>tt[2]) and (tt[4]<>tt[3]);
repeat
tt[5]:=random(12)+1
until (tt[5]<>tt[1]) and (tt[5]<>tt[2]) and (tt[5]<>tt[3]) and (tt[5]<>tt[4]);
repeat
tt[6]:=random(12)+1
until (tt[6]<>tt[1]) and (tt[6]<>tt[2]) and (tt[6]<>tt[3]) and (tt[6]<>tt[4])
and (tt[6]<>tt[5]);
repeat
tt[7]:=random(12)+1
until (tt[7]<>tt[1]) and (tt[7]<>tt[2]) and (tt[7]<>tt[3]) and (tt[7]<>tt[4])
and (tt[7]<>tt[5]) and (tt[7]<>tt[6]);
repeat
tt[8]:=random(12)+1
until (tt[8]<>tt[1]) and (tt[8]<>tt[2]) and (tt[8]<>tt[3]) and (tt[8]<>tt[4])
and (tt[8]<>tt[5]) and (tt[8]<>tt[6]) and (tt[8]<>tt[7]);
repeat
tt[9]:=random(12)+1
until (tt[9]<>tt[1]) and (tt[9]<>tt[2]) and (tt[9]<>tt[3]) and (tt[9]<>tt[4])
and (tt[9]<>tt[5]) and (tt[9]<>tt[6]) and (tt[9]<>tt[7]) and (tt[9]<>tt[8]);
repeat
tt[10]:=random(12)+1
until (tt[10]<>tt[1]) and (tt[10]<>tt[2]) and (tt[10]<>tt[3]) and (tt[10]<>tt[4])
and (tt[10]<>tt[5]) and (tt[10]<>tt[6]) and (tt[10]<>tt[7]) and (tt[10]<>tt[8])
and (tt[10]<>tt[9]);
repeat
tt[11]:=random(12)+1
until (tt[11]<>tt[1]) and (tt[11]<>tt[2]) and (tt[11]<>tt[3]) and (tt[11]<>tt[4])
and (tt[11]<>tt[5]) and (tt[11]<>tt[6]) and (tt[11]<>tt[7]) and (tt[11]<>tt[8])
and (tt[11]<>tt[9]) and (tt[11]<>tt[10]);
repeat
tt[12]:=random(12)+1
until (tt[12]<>tt[1]) and (tt[12]<>tt[2]) and (tt[12]<>tt[3]) and (tt[12]<>tt[4])
and (tt[12]<>tt[5]) and (tt[12]<>tt[6]) and (tt[12]<>tt[7]) and (tt[12]<>tt[8])
and (tt[12]<>tt[9]) and (tt[12]<>tt[10]) and (tt[12]<>tt[11]);
str(a,calcstr1);
for k:= 1 to 12 do begin
str(tt[k],calcstr2);
str(tt[k]*a,calcstr3);
form1.canvas.textout(0,k*30+80,' '+calcstr2+' times '+calcstr1+' = '+calcstr3+'');
end;
1: end;
end.
Wednesday, September 10, 2025
Random times tables in Delphi
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment