PROGRAMME QUATORZE
Soit la liste suivante de salaires stockée dans un tableau,
210.33 119.78 191.05 222.94
Calculez la répartition nécessaire en pièces de 50c, 20c, 10c, 5c, 2c, et 1c
(ignorez la partie entière du nombre).
program PROG14 (output); {programme monnaie}
var wages : array[1..6] of real;
cents : real;
loop, fiftys, twentys, tens, fives, twos, ones : integer;
begin
{initialisation des salaires}
wages[1] := 210.33; wages[2] := 119.78;
wages[3] := 191.05; wages[4] := 222.94;
wages[5] := 0.0; { premier chiffre non significatif du tableau}
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('Le nombre total de pièces nécessaire est');
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-1995. Tous droits réservés.
Copyright UCL/INGI, 1995. Tous droits réservés
URL: http://candix1.fsa.ucl.ac.be/langages/Pascal/tutoriel/pas038a.htm