
Programa que escriba en letras un numero digitado
Publicado por alvaro (4 intervenciones) el 19/04/2014 04:09:12
Ayuda con este codigo, para pasar de numeros a letras, el problema que tengo es que me da un error a la hora de escribir los cietntos y el numero eje, 102 lo pone como uno dos, me explico, con los demas de momento me los escribe bien,
saludes...
program numerosletras;
uses crt;
const sim = ('-----------------------------------------------------------------------');
const u : array[1..9] of string = ('uno','dos','tres','cuatro','cinco','seis','siete','ocho','nueve');
const d : array[1..9] of string = ('diez','veinte','treinta','cuarenta','cincuenta',
'sesenta','setenta','ochenta','noventa');
const dy : array[1..5] of string = ('once','doce','trece','catorce','quince');
const c : array[1..9] of string = ('ciento ','','','','','','','','');
procedure unidadproc (cantidad : longint);
var unidad, decena, centena : longint;
begin
unidad := cantidad mod 10;
decena := (cantidad div 10) mod 10;
centena := (cantidad div 100) mod 10;
if c[centena] = '' then {cambia centenas}
write (u[centena], 'cientos ') {escribe los cientos}
else
if (centena <> 1) or (unidad <> 0) or (decena <> 0) then
write (u[centena]){centenas}
else
write ('cien');
if (unidad <> 0) or (decena <> 0) then
begin
if centena <> 0 then
write('');
if decena = 0 then
write(u[unidad])
else
if unidad = 0 then
write (d[decena])
else
if (decena = 1) and (unidad >= 1) and (unidad <= 5) then
write (dy[unidad])
else
if decena = 1 then
write ('dieci', u[unidad])
else
if decena = 2 then
write('veinti', u[unidad])
else
write (d[decena], ' y ' , u[unidad]);
end;
end;
procedure milproc (cantidad : longint);
var unidades, miles : longint;
begin
unidades := cantidad mod 1000;
miles := (cantidad div 1000) mod 1000;
if miles > 1 then
unidadproc(miles);
if miles <> 0 then
write (' mil');
if (unidades <> 0) and (miles <> 0) then
write(' ');
unidadproc(unidades);
end;
procedure millonproc(cantidad:longint);
var unidades, millares:longint;
begin
unidades := cantidad mod 1000000;
millares := (cantidad div 1000000) mod 1000000;
if millares > 1 then
begin
milproc(millares);
write(' millones');
end
else if millares <> 0 then
write('un millon');
if (unidades <> 0) and (millares <> 0) then
write (' ');
milproc(unidades);
end;
{main principal--------------------}
var cantidad : longint;
tecrep : char;
begin
repeat
clrscr;
writeln;
textcolor(7);
writeln(sim);
writeln('PROGRAMA QUE REESCRIBE SU NUMEROS A LETRAS');
writeln(sim);
textcolor(6);
write('Digite una Cantidad: ');
readln(cantidad);
textcolor(7);
writeln(sim);
write('El numero en letras es: ');
if cantidad < 0 then
begin
write ('menos ');
cantidad := cantidad;
end;
if cantidad = 0 then
write ('cero')
else
millonproc(cantidad);
writeln;
textcolor(7);
writeln(sim);
textcolor(6); {magenta}
writeln('Desea empezar de nuevo S / N');
tecrep := readkey;
until (tecrep = 'N') or (tecrep = 'n');
end.
saludes...
program numerosletras;
uses crt;
const sim = ('-----------------------------------------------------------------------');
const u : array[1..9] of string = ('uno','dos','tres','cuatro','cinco','seis','siete','ocho','nueve');
const d : array[1..9] of string = ('diez','veinte','treinta','cuarenta','cincuenta',
'sesenta','setenta','ochenta','noventa');
const dy : array[1..5] of string = ('once','doce','trece','catorce','quince');
const c : array[1..9] of string = ('ciento ','','','','','','','','');
procedure unidadproc (cantidad : longint);
var unidad, decena, centena : longint;
begin
unidad := cantidad mod 10;
decena := (cantidad div 10) mod 10;
centena := (cantidad div 100) mod 10;
if c[centena] = '' then {cambia centenas}
write (u[centena], 'cientos ') {escribe los cientos}
else
if (centena <> 1) or (unidad <> 0) or (decena <> 0) then
write (u[centena]){centenas}
else
write ('cien');
if (unidad <> 0) or (decena <> 0) then
begin
if centena <> 0 then
write('');
if decena = 0 then
write(u[unidad])
else
if unidad = 0 then
write (d[decena])
else
if (decena = 1) and (unidad >= 1) and (unidad <= 5) then
write (dy[unidad])
else
if decena = 1 then
write ('dieci', u[unidad])
else
if decena = 2 then
write('veinti', u[unidad])
else
write (d[decena], ' y ' , u[unidad]);
end;
end;
procedure milproc (cantidad : longint);
var unidades, miles : longint;
begin
unidades := cantidad mod 1000;
miles := (cantidad div 1000) mod 1000;
if miles > 1 then
unidadproc(miles);
if miles <> 0 then
write (' mil');
if (unidades <> 0) and (miles <> 0) then
write(' ');
unidadproc(unidades);
end;
procedure millonproc(cantidad:longint);
var unidades, millares:longint;
begin
unidades := cantidad mod 1000000;
millares := (cantidad div 1000000) mod 1000000;
if millares > 1 then
begin
milproc(millares);
write(' millones');
end
else if millares <> 0 then
write('un millon');
if (unidades <> 0) and (millares <> 0) then
write (' ');
milproc(unidades);
end;
{main principal--------------------}
var cantidad : longint;
tecrep : char;
begin
repeat
clrscr;
writeln;
textcolor(7);
writeln(sim);
writeln('PROGRAMA QUE REESCRIBE SU NUMEROS A LETRAS');
writeln(sim);
textcolor(6);
write('Digite una Cantidad: ');
readln(cantidad);
textcolor(7);
writeln(sim);
write('El numero en letras es: ');
if cantidad < 0 then
begin
write ('menos ');
cantidad := cantidad;
end;
if cantidad = 0 then
write ('cero')
else
millonproc(cantidad);
writeln;
textcolor(7);
writeln(sim);
textcolor(6); {magenta}
writeln('Desea empezar de nuevo S / N');
tecrep := readkey;
until (tecrep = 'N') or (tecrep = 'n');
end.
Valora esta pregunta


0