饮料自动售货机(delphi版)

 

                      //要找的金额;零钱开始的下标;零钱的面值
                      //零钱的种类;剩余零钱的数量;找零的结果
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.

本文出自 “迷茫后的短暂停留” 博客,谢绝转载!

你可能感兴趣的:(职场,Delphi,休闲,饮料自动售货机)