Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Why my pascal program keeps repeating?

+5 votes
asked Jun 9 by Lamborghini Veneno (170 points)
I made this program on pascal , the problem is that in the procedure "llenarLista" it keeps repeating even if I put the A.DNI in 33555444

program Casting;

type Gen = 1..5;

Aspirantes = Record DNI:Integer;

Nom:Char;

Ape:Char;

Edad:Integer;

Genero:Gen;

end;

Lista = ^nodo;

Nodo = Record Dato:Aspirantes;

Sig:Lista;

end;

procedure leerAspirantes (var A:Aspirantes);

begin writeLN ('Inserte DNI');

readLN (A.DNI);

WriteLN ('Inserte Nombre y Apellido');

readLN (A.Nom);

readLN (A.Ape);

WriteLN ('Inserte Edad');

readLN (A.Edad);

WriteLN ('Inserte genero de pelicula');

readLN (A.Genero);

end;

procedure agregarElemento (A:Aspirantes;

var L:    Lista);

var nuevo:Lista;

begin new (nuevo);

nuevo ^.dato:= A;

nuevo ^.sig:= nil;

if (L = nil)

then L:= nuevo

  else

begin nuevo ^.sig:= L;

L:= nuevo;

end;

end;

procedure llenarLista (var L:Lista);

var A:Aspirantes;

begin repeat leerAspirantes (A);

agregarElemento (A, L);

until (A.DNI = 33555444);

end;

var L:Lista;

begin L:= nil;

llenarLista (L);

end.

1 Answer

0 votes
answered Jun 12 by Peter Minarik (54,560 points)
edited Jun 12 by Peter Minarik

After some testing, it looks like the Integer type on Online GDB's Pascal is really just a SmallInt (16-bit signed integer). Hence, it cannot store such a large number as 33555444.

Instead of Integer (, which is probably just a name for another type, depending on compiler options), try to use LongInt (32-bit signed integer) specifically for your DNI and your problem should be solved.

Here is a reference for data types.

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...