饮料自动售货机(delphi版)

2016-08-22 10:20:51来源:http://suguiyang.blog.51cto.com/1035725/416993作者:su_guiyang人点击




//要找的金额;零钱开始的下标;零钱的面值
//零钱的种类;剩余零钱的数量;找零的结果
function Give_Change( balance:Integer; start:Integer; changesValue:array of Integer;
changesType:Integer; var changesCount,changesResult:array of Integer):Boolean;
var
index: Integer;
flag : Boolean;
balance_temp : Integer;
begin
flag := False;
while (flag = False) and (start >= 0) do
begin
balance_temp := balance;
for index :=0 to changesType-1 do
changesResult[index] := 0;
index := start;
while (index >=0) do
begin
flag := False;
changesResult[index] := balance_temp div changesValue[index];
if changesResult[index] > changesCount[index] then
changesResult[index] := changesCount[index];
balance_temp := balance_temp - changesResult[index]*changesValue[index];
index := index -1;
if ( balance_temp <=0 ) then
begin
flag := true;
Break;
end;
end;
start := start -1;
end;
if flag then
begin
for index:=0 to 5 do
changesCount[index] := changesCount[index] - changesResult[index];
result := true;
end
else
Result := false;
end;
end.


最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台