全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:817
推到 Plurk!
推到 Facebook!

Please help me on Delphi.

答題得分者是:st33chen
turbomen
一般會員


發表:5
回覆:4
積分:1
註冊:2009-04-04

發送簡訊給我
#1 引用回覆 回覆 發表時間:2009-04-04 08:59:34 IP:202.49.xxx.xxx 訂閱
Please help me on Delphi.  I am a new comer to this website and to Delphi.  The following is the question:

I need to create an array of 6 lotto numbers. The numbers should be between 1 and 40 and I am not allowed to put into the array any number that is already in it. Hint: I am using an array of 6 numbers so that's a loop generate a temporary number
while that numbers is already in the lotto array regenerate it
put my temporary number in the current slot of the array.

Cheers,

Tony
st33chen
尊榮會員


發表:15
回覆:591
積分:1201
註冊:2005-09-30

發送簡訊給我
#2 引用回覆 回覆 發表時間:2009-04-04 14:50:53 IP:61.62.xxx.xxx 未訂閱
hi,

please try this

var
iarray : array[1..6] of integer;
ii, jj, kk, anum : integer;
begin
iarray[1] := random(40) 1; // generate the 1st random number
for ii := 2 to 6 do begin // generate other numbers
kk :=1;
while kk=1 do begin
anum := random(40) 1; // generate a number
for jj := 1 to ii-1 do begin
if iarray[jj]=anum then break; // test if anum is in the current iarray
end;
if jj=ii then begin // anum is not in the current iarray
iarray[ii] := anum; // add anum to iarray
kk := 2; // get out from the while loop to process the next number
end;
end;
end;
end;

===================引 用 turbomen 文 章===================
Please help me on Delphi. I am a new comer to this website and to Delphi. The following is the question:

I need to create an array of 6 lotto numbers. The numbers should be between 1 and 40 and I am not allowed to put into the array any number that is already in it. Hint: I am using an array of 6 numbers so that's a loop generate a temporary number
while that numbers is already in the lotto array regenerate it
put my temporary number in the current slot of the array.

Cheers,

Tony
------
IS IT WHAT IT IS
我是 李慕白 請倒著唸.
又想把老話拿出來說, 請用台語發音 : 專家專家全是ROBOT CAR (滷肉腳啦);
都已接手這麼久了, 績效還是那麼爛, 講話還那麼大聲.
編輯記錄
st33chen 重新編輯於 2009-04-05 08:50:14, 註解 無‧
turbomen
一般會員


發表:5
回覆:4
積分:1
註冊:2009-04-04

發送簡訊給我
#3 引用回覆 回覆 發表時間:2009-04-04 19:47:28 IP:222.152.xxx.xxx 訂閱
Hi st33chen,

Thank you for your kind help. But I do not know why it does not work.

Cheers,

Tony
===================引 用 st33chen 文 章===================
hi,

please try this

var
iarray : array[7] of integer;
ii, jj, kk, anum : integer;
begin
iarray[1] := random(40) 1; // generate the 1st random number
for ii := 2 to 6 do begin // generate other numbers
kk :=1;
while kk=1 do begin
anum := random(40) 1; // generate a number
for jj := 1 to ii-1 do begin
if iarray[jj]=anum then break; // test if anum is in the current iarray
end;
if jj=ii then begin // anum is not in the current iarray
iarray[ii] := anum; // add anum to iarray
kk := 2; // get out from the while loop to process the next number
end;
end;
end;
end;

===================引 用 turbomen 文 章===================
Please help me on Delphi. I am a new comer to this website and to Delphi. The following is the question:

I need to create an array of 6 lotto numbers. The numbers should be between 1 and 40 and I am not allowed to put into the array any number that is already in it. Hint: I am using an array of 6 numbers so that's a loop generate a temporary number
while that numbers is already in the lotto array regenerate it
put my temporary number in the current slot of the array.

Cheers,

Tony
系統時間:2024-05-18 14:31:18
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!