Here's what I would do...
SCAR Code:
procedure GetAmounts;
Money:= Money/2; // You could also use Money shr 1;
AmountItem1ToBuy:= Money/Item1Price;
AmountItem2ToBuy:= Money/Item2Price;
if(AmountItem1ToBuy > AmountItem2ToBuy)then
begin
AmountItem1ToBuy:= AmountItem2ToBuy;
end else
begin
AmountItem2ToBuy:= AmountItem1ToBuy;
end;
end;
procedure GetFinalAmounts;
begin
repeat
GetAmounts;
Cost:= AmountItem1ToBuy*Item1Price;
Cost:= Cost+(AmountItem2ToBuy*Item2Price);
Money:= Money*2;
Money:= Money-Cost;
until((Item1Cost+Item2Cost) >= Money);
end;
begin
GetFinalAmounts;
end.
Post if you have questions! Rep+