Here's the solution, without the unnecessary conversion to string. It works by obtaining the right-most digit, adding its value to the accumulator Total
, and then removing the rightmost digit by performing an integer division by 10, and repeating the process until we have nothing left.
var
Value, Digit, Total, NumValues: Integer;
i: Integer;
begin
NumValues := 0;
for i := 1 to 1000 do
begin
Value := i;
Total := 0;
repeat
Digit := Value mod 10;
Total := Total + Digit;
Value := Value div 10;
until Value = 0;
if Total = 6 then
Inc(NumValues);
end;
WriteLn ('I found ', NumValues, ' numbers whose digits add up to six');
ReadLn;
end.