natknalem sie na maly problem podczas pisania odejmowania dla dlugich liczb na stringach. w miejscu gdzie juz mam konkretnie odejmowac niby powinno mi dzialac, a jednak nie dziala:| kto mi moze pomoc? mój kod:
function substraction(a, b : String) : String;
var
i, temp : Byte;
ad, bd : Byte;
flag, sign : Boolean;
S : String;
begin
sign:=TRUE;
if length(b) > length(a) then
begin
Replace(a, b);
sign:=FALSE;
end;
if length(a) = length(b) then
begin
flag:=TRUE;
i:=1;
while (flag <> FALSE) and (i <= length(a)) do
begin
if toDigit(b[i]) > toDigit(a[i]) then
flag:=FALSE;
inc(i);
end;
if flag = FALSE then
begin
Replace(a, b);
sign:=FALSE;
end;
end;
S:='';
while length(a) > length(b) do
b:='0' + b;
while length(b) > length(a) do
a:='0' + a;
for i:=length(a) downto 2 do
begin
ad:=toDigit(a[i]);
bd:=toDigit(b[i]);
if ad < bd then
begin
temp:=ad - bd + 10;
a[i - 1]:=toChar(toDigit(a[i - 1]) - 1);
end else
temp:=ad - bd;
S:=toChar(temp) + S;
end;
S:=toChar(toDigit(a[1]) - toDigit(b[1])) + S;
if sign = FALSE then
S:='-' + S;
substraction:=S;
end;
procka Replace(var a, b) zamienia wartosciami dwa lancuchy, a toDigit i toChar chyba tlumaczyc nie trzeba.