program telephone;
uses wincrt;
var
n:string;
procedure numero (var n:string);
var
ch1,ch2:string;
begin
str(random(9000)+1000,ch1);
str(random(9000)+1000,ch2);
n:=ch1+ch2;
end;
function verif(ch:string):boolean;
var
i:integer;
test:boolean;
begin i:=0;
repeat i:=i+1;
test:=ch[i] in ['0'..'9'];
until (i=length(ch)) or (test=false);
verif:=test;
end;
Procedure affiche (VAR ch:string;n:string;chif:char);
begin
while (pos(chif,n)<>0) do begin
ch[pos(chif,n)]:=chif;
n[pos(chif,n)]:='X';
end;
writeln(ch);
end;
procedure devine (n:string);
var
nb:integer;
chif,rep:char;
trouve:integer;
ch,num:string;
begin
ch:='---';
nb:=0;
repeat nb:=nb+1;
repeat
write('Proposer un chiffre entre 0..9');
readln(chif);
until chif in ['0'..'9'];
affiche(ch,n,chif);
TROUVE:=0;
repeat
write('Voulez-vous proposer un numero ?');
readln(rep);
until rep in ['N','O'];
if rep='O' then begin
repeat
write('Proposer un Numero :');
readln(num);
until (length(num)=8) and (verif(num));
if num=n then trouve:=1 else
trouve:=2;
end;
until (nb=5)or ( trouve=2)OR (trouve=1);
if (trouve = 2) or (nb=5) then
writeln('Desole ! vous avez perdu ');
if (nb<=5) and (trouve=1) then
writeln('Bravo ! Vous avez gagne');
end;
begin numero(n);
writeln(n);
devine(n);
end.