Pascal/Turbo Pascal - corrección_ejercicio_arrays_pascal

 
Vista:
Imágen de perfil de santix

corrección_ejercicio_arrays_pascal

Publicado por santix (1 intervención) el 19/10/2016 21:34:46
Hola a todos, por favor si alguien podría ayudarme a ver porque motivo se cae la ejecución de este código, se agradece.

Enunciado:
3-Escribir un programa en Pascal que solicite por teclado los valores correspondientes a las ventas
parciales de cada mes (el mismo mes puede cargarse más de una vez), correspondiente a un año
completo, desde Enero hasta Diciembre (no todos los meses pueden tener monto). Informar un listado
ordenado por mes de los montos totales mensuales (suma de ventas parciales), y los montos promedio
mensuales. Informar el monto total de ventas.

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
PROGRAM TPVEC_EJ3;
USES CRT;
TYPE
    MES=ARRAY [1..12] OF string;
    VENTA=ARRAY [1..12] OF real;
    PROM = ARRAY [1..12]OF integer;
 
VAR i: integer; adventa:char;
    total:real; pventa:real; nMes:integer;
    VMES: MES;
    VVENTA:VENTA;
    PPROM: PROM;
 
BEGIN
 
    begin
 
        vmes[1]:='(1) Enero';
        vmes[2]:='(2) Febrero';
        vmes[3]:='(3) Marzo';
        vmes[4]:='(4) Abril';
        vmes[5]:='(5) Mayo';
        vmes[6]:='(6) Junio';
        vmes[7]:='(7) Julio';
        vmes[8]:='(8) Agosto';
        vmes[9]:='(9) Septiembre';
        vmes[10]:='(10) Octubre';
        vmes[11]:='(11) Noviembre';
        vmes[12]:='(12) Diciembre';
 
        FOR i:=1 to 12 DO
            begin
            writeln (vmes[i]);
            vventa[i]:=0;
            total:=0;
			end;
    end;
 
    REPEAT //DATOS PEDIR
        writeln;
        writeln('INGRESAR MES (numero) ');
        readln(nMes);
        writeln ('CARGAR VENTA PARA MES ', vmes[nMes] );
        vmes[i]:=vmes[nMes];
        readln (pventa);
 
        //CALCULAR
        total:=total+pventa;
        vventa[nMes]:= vventa[nMes] + pventa;
        pprom[nMes]:=pprom[nMes]+1;
        writeln('cargar otra venta? S/N');
        readln (adventa);
    UNTIL adventa = ('N');
 
    writeln ('INFORME');
    writeln ('VENTAS PARCIALES');
 
//MOSTRAR
        begin
        IF vventa[i] = 0 then
            writeln (vmes[i], ' = NO HAY VENTA  ') ELSE
            writeln ( vmes[i],' $ = ' ,vventa[i] :5:2 , '(',pprom[i],')');
            writeln(' Promedio de ventas mensuales: ', vmes[i], ' = $ ',vventa[i]/pprom[i] :5:2);
    end;
    writeln; writeln ('TOTAL VENTAS $ = ', total :5:2); writeln;
    readkey;
 
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

corrección_ejercicio_arrays_pascal

Publicado por ramon (2158 intervenciones) el 19/10/2016 23:40:59
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
{Mira las correcciones}
 
PROGRAM TPVEC_EJ3;
USES CRT;
TYPE
MES=ARRAY [1..12] OF string;
VENTA=ARRAY [1..12] OF real;
PROM = ARRAY [1..12]OF integer;
 
VAR i: integer; adventa:char;
total:real; pventa:real; k, nMes:integer;
VMES: MES;
VVENTA:VENTA;
PPROM: PROM;
tecla, pulsa : char;
 
BEGIN
      vmes[1] := '(1) Enero';
      vmes[2] := '(2) Febrero';
      vmes[3] := '(3) Marzo';
      vmes[4] := '(4) Abril';
      vmes[5] := '(5) Mayo';
      vmes[6] := '(6) Junio';
      vmes[7] := '(7) Julio';
      vmes[8] := '(8) Agosto';
      vmes[9] := '(9) Septiembre';
      vmes[10] := '(A) Octubre';
      vmes[11] := '(B) Noviembre';
      vmes[12] := '(C) Diciembre';
      k := 0;
      FOR i := 1 to 12 DO
      begin
         vventa[i]:=0;
         total:=0;
      end;
  repeat
   clrscr;
   FOR i := 1 to 12 DO
   begin
      writeln('    ',vmes[i]);
    end;
   {//DATOS PEDIR}
   writeln;
   write('   INGRESAR (Opcion) MES  ');
   repeat
        tecla := upcase(readkey);
   until tecla in['1','2','3','4','5','6','7','8','9','A','B','C'];
   if tecla in['1'..'9'] then
   k := ord(tecla) - 48
 else
   k := ord(tecla) - 55;
   nmes := k;
   k := 0;
   write('   CARGAR VENTA PARA MES ', vmes[nMes],' : ');
   vmes[i] := vmes[nMes];
   readln(pventa);
 
  {//CALCULAR}
     total := total + pventa;
     vventa[nMes] := vventa[nMes] + pventa;
     pprom[nMes] := pprom[nMes] + 1;
     writeln('cargar otra venta? S/N');
     repeat
        pulsa := readkey;
     UNTIL upcase(pulsa) in['N','S'];
  until upcase(pulsa) = 'N';
  clrscr;
      writeln ('INFORME');
      writeln ('VENTAS PARCIALES');
 
      {//MOSTRAR}
    for i := 1 to 12 do
    begin
     IF vventa[i] = 0 then
     writeln (vmes[i], ' = NO HAY VENTA ')
  ELSE
   begin
     writeln ( vmes[i],' $ = ' ,vventa[i] :5:2 , '(',pprom[i],')');
     writeln(' Promedio de ventas mensuales: ', vmes[i], ' = $ ',
                                               vventa[i]/pprom[i] :5:2);
     end;
  end;
   writeln; writeln ('TOTAL VENTAS $ = ', total :5:2); writeln;
   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
2
Comentar
Imágen de perfil de santix

corrección_ejercicio_arrays_pascal

Publicado por santix (1 intervención) el 20/10/2016 23:53:58
Ramon,
Muchas gracias por tu respuesta.
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