The following code is supposed to divide a sum of money (e.g. : 325.200) into cards of 50, 10, 5 and 1. The rest (the decimal part being shown separately).
program Cards;
uses wincrt;
var
d50, d10, d5, d1, dm: integer;
s: real;
begin
readln(s);
d50 := trunc(s) div 50;
d10 := trunc(s) mod 50 div 10;
d5 := trunc(s) mod 10 div 5;
d1 := trunc(s) mod 5;
dm := trunc((frac(s) * 1000));
writeln('50: ', d50, ' 10: ', d10, ' 5: ', d5, ' 1: ', d1, ' m: ', dm);
end.
A problem arises with the sum 356.200. The shown dm
is 199 instead of 200.