uses crt;
const
alfabeto: array[1..27] of Char = ( 'A', 'B', 'C', 'D', 'E',
'F','G', 'H', 'I', 'J', 'K', 'L', 'M', 'N','', 'O', 'P',
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');
max = 30; {this is used for declaring ARRAY}
type
hexadecimal = ARRAY[1..max] OF integer;
var
decimal: longint;
i: integer;
hexa: hexadecimal;
tecla : char ;
operacion, nn : longint ;
palabra : string[30] ;
(***********************************************)
(* Function convierte un caracter en mayuscula *)
(***********************************************)
function mayuscula(caracter : char ): char;
begin
if ( char(caracter) = '' ) then
begin
caracter := '' ;
end;
mayuscula := upcase(caracter);
end;
(*******************************************************)
(* Function retorna un valor dependiendo del caracter *)
(*******************************************************)
function posicion(caracter : char ): integer;
var
su, i: Integer;
begin
su := 0;
for i := 1 to 27 do
begin
if (alfabeto[i] = mayuscula(caracter)) then
begin
su := i;
end ;
end;
posicion := su;
end;
function cantidad(S: string): longint ;
var
I: Integer;
suma : longint ;
begin
suma := 0;
for I := 1 to Length(S) do
begin
suma := suma + posicion(S[I]);
end;
cantidad := suma ;
end;
PROCEDURE convert(decimal: longint; VAR i: integer; VAR hexa: hexadecimal);
{This procedure works the conversion}
BEGIN
i := 1;
WHILE decimal <> 0 DO
BEGIN
hexa[i] := decimal MOD 16;
decimal := decimal DIV 16;
i := i + 1;
END;
END;
PROCEDURE writetothescreen(i: integer; hexa: hexadecimal);
VAR j: integer;
BEGIN
write( 'Convertido ',' ', ' en hexadecimal es ');
{This is how you make a hex number}
FOR j := (i - 1) DOWNTO 1 DO BEGIN
IF hexa[j] < 10 THEN
write(output, hexa[j])
ELSE BEGIN
{Here, program checks for number larger than 10 to write a letter instead of number}
CASE hexa[j] OF
10: write(output, 'A');
11: write(output, 'B');
12: write(output, 'C');
13: write(output, 'D');
14: write(output, 'E');
15: write(output, 'F');
END; {End of Case}
END; {End of ELSE}
END; {End of FOR loop}
END; {End of Procedure}
(************************)
(* Programa principal *)
(************************)
begin
clrscr;
repeat
clrscr;
writeln;
writeln;
write('Ingrese una palabra: ');
ReadLn(palabra);
write(' ',palabra ,' = ',cantidad(palabra) );
writeln;
writeln;
write('Ingrese un numero: ');
ReadLn(nn);
operacion := cantidad(palabra) * nn;
writeln;
writeln;
write(cantidad(palabra) , ' * ', nn ,' = ', operacion );
writeln;
writeln;
convert(operacion, i, hexa);
write(operacion , ' ' );
writetothescreen(i, hexa);
writeln;
writeln;
write('Desea introducir otra palabra [S/N]');
tecla := mayuscula( Readkey);
until ( tecla <> 'S');
end.