1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
program final;
{$APPTYPE CONSOLE}
uses
sysutils;
var
nbch, i, basedep, basefin, reste, quotient : integer;
ch, rep,resultat, nb : string;
erreur, controlsaisie : boolean;
function control (nb:string;basedep:integer):boolean;
begin
nbch:=length(nb);
i:=1;
erreur:= false;
while (not erreur) and (i <= nbch) do
begin
ch:= copy(nb,i,1);
if (StrToInt(ch) > 0) and (StrToInt(ch) < BaseDep - 1)
then erreur:= true ;
end;
end;
function conver (basedep,basefin:integer;nb:string):string;
begin
if (basedep=16) and (StrToInt(ch)>=10)
then ch:= Chr(StrToInt(ch));
quotient := StrToInt(nb) div basefin;
reste := StrToInt(nb) mod basefin;
result := intToStr(quotient) + intToStr(reste);
end;
begin
write('voulez-vous effectuer une conversion ? o/n:');
readln(rep);
while rep = 'o' do
begin
write('saisir un nombre:');
readln(nb);
write ('base de depart:');
readln(basedep);
write ('base de fin:');
readln(basefin);
controlsaisie:= control (nb,basedep);
if controlsaisie = true
then writeln('erreur saisie')
else resultat:= conver(basedep,basefin,nb);
writeln('resultat:',resultat);
write('voulez-vous effectuer une autre conversion ? o/n:');
readln(rep);
end;
end. |
Partager