PROGRAM FOURTEEN
Given the following list of wages stored in an array,
210.33 119.78 191.05 222.94
calculate the total breakdown of required coins (ignore dollars) into
50c, 20c, 10c, 5c, 2c, and 1c pieces.
program PROG14 (output); {coin program}
var wages : array[1..6] of real;
cents : real;
loop, fiftys, twentys, tens, fives, twos, ones : integer;
begin
{initialise wages}
wages[1] := 210.33; wages[2] := 119.78;
wages[3] := 191.05; wages[4] := 222.94;
wages[5] := 0.0; { end of wage terminator }
loop := 1;
fiftys := 0; twentys := 0; tens := 0; fives := 0; twos := 0;
ones := 0;
while (wages[loop] <> 0.0 ) do
begin
cents := wages[loop] - trunc( wages[loop] ); {get cents}
while cents >= 0.4999 do
begin
fiftys := fiftys + 1;
cents := cents - 0.50
end;
while cents >= 0.1999 do
begin
twentys := twentys + 1;
cents := cents - 0.20
end;
while cents >= 0.0999 do
begin
tens := tens + 1;
cents := cents - 0.10
end;
while cents >= 0.0499 do
begin
fives := fives + 1;
cents := cents - 0.05
end;
while cents >= 0.0199 do
begin
twos := twos + 1;
cents := cents - 0.02
end;
while cents >= 0.00999 do
begin
ones := ones + 1;
cents := cents - 0.01
end;
loop := loop + 1
end;
writeln;
writeln('The total breakdown of coins required is');
writeln(' 50c 20c 10c 5c 2c 1c');
writeln(fiftys:7,twentys:7,tens:7,fives:7,twos:7,ones:7)
end.
Copyright B Brown/P Henry/CIT, 1988-1997. All rights reserved.