Pascal/Turbo Pascal - Programa que escriba en letras un numero digitado

 
Vista:
sin imagen de perfil

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.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

Programa que escriba en letras un numero digitado

Publicado por ramon (2158 intervenciones) el 19/04/2014 19:04:11
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
{Mira estas modificación ajusta lo a tu manera}
 
 uses
     crt;
   const
      unid : array[1..9] of string[6] = (
      'uno','dos','tres','cuatro','cinco','seis','siete','ocho','nueve');
      dece : array[1..9] of string[9] = (
      'diez','veinti','treinta','cuarenta','cincuenta','sesenta',
      'setenta','ochenta','noventa');
      cent : array[1..9] of string[12] = (
      'ciento','doscientos','trascientos','cuatricientos','quinientos',
      'seiscirntos','setecientos','ochocientos','novecientos');
 
 
  var
    unidad, decena, centena : longint;
    num : longint;
 
   procedure unidades(numero : longint);
   begin
      unidad := numero mod 10;
      decena := (numero div 10) mod 10;
      centena := (numero div 100) mod 10;
      if (centena = 0) and (decena = 0) then
      write(unid[unidad]);
      if (centena = 0) and (decena > 0) then
      write(dece[decena],unid[unidad]);
      if (centena > 0) and (decena >= 0) then
      if decena = 0 then
      write(cent[centena],dece[decena],unid[unidad])
    else
      write(cent[centena],dece[decena],'i',unid[unidad]);
   end;
 
   procedure milproc (cantidad : longint);
    var
      unidades1, miles : longint;
    begin
      unidades1 := cantidad mod 1000;
      miles := (cantidad div 1000) mod 1000;
     if miles > 1 then
      unidades(miles);
      if miles <> 0 then
       write(' mil');
       if (unidades1 <> 0) and (miles <> 0) then
       write(' ');
       unidades(unidades1);
    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;
 
 
   begin
      clrscr;
      write('   Entre Numero : ');
      readln(num);
   if num < 0 then
   begin
    write('menos ');
     num := num;
   end;
   if num = 0 then
   write('cero')
  else
    millonproc(num);
 
      readkey;
   end.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar