Forum > Beginners

type [SOLVED]

(1/2) > >>

Raffyn:
Hello, I have a problem with my code and don't know why it isn't working or at least I don't see the mistake.

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program VerbundFeldKombi;uses crt;type person = record             n: string;             a: string;             t: string;     end;type feld = array[1..30] of person;var ds:feld;    i, j, z: integer;    temp: person; begin clrscr; {Eingabe} write('Anzahl der einzugebeneden Datensaetze: '); read(z);  for i:= 1 to z do  with ds[i] do   begin    writeln('Name, Vorname eingeben: ');    readln(n);    writeln('Plz, Ort, Str., Nr. eingeben: ');    readln(a);    writeln('Telefonnr. eingeben: ');    readln(t);   end;clrscr;{Sortieren} for i:= 1 to z-1 do for j:=z downto i do  with ds[i] do   if ds[i].n > ds[j].n then    begin     temp:=ds[i];     ds[i]:=ds[j];     ds[j]:=temp;    end;{Anzeigen}for i:= 1 to z do with ds[i] do  begin   writeln('Name, Vorname: ', n);   writeln('Anschrift: ', a);   writeln('Telefon: ',t);  end; readkey;end.
It's supposed to insert first information then second then third but when runs it shows both the first and second request at once.
Thank you Raffy

Bart:
Change read(z) into readln(z), this will "consume" the Enter key.

B.t.w: the topic title ("type") isn't very helpfull.
A good topic title describes the proble you are seeking help for e.g.
"How to sotr an array?"
"Why does this piece of code crash?"

Bart

MarkMLl:

--- Quote from: Bart on May 16, 2021, 10:36:30 pm ---B.t.w: the topic title ("type") isn't very helpfull.

--- End quote ---

But he gets credit for putting his failing code in a code box, and giving the community a complete program which can be checked easily.

MarkMLl

pascal111:
أعتقدُ أنّي قرأتُ مرّةً في الـ Help الخاص بالـ Turbo Pascal أنّ read تختلف عن readln في أنّها لا تُضيف لبنة نهاية السطر (تغذية السطر) وأنّ ذلكـ يُحدث مُشكلةً في عبارات الـ readln التالية إذا كانت القراءة من الـ console أي تقريباً لا يُفضّل إستخدام read في القراءة من الـ console.

google translate:

"I think I once read in the Help for "of" Turbo Pascal that read differs from readln in that it does not add an end-of-line block "character" (line feed) and that this creates a problem in the following readln statements if reading from the console i.e. almost not preferring to use read for reading, From "from" the console."

lucamar:

--- Quote from: pascal111 on May 16, 2021, 11:12:39 pm ---I think I once read in the Help for "of" Turbo Pascal that read differs from readln in that it does not add an end-of-line block "character" (line feed) and that this creates a problem in the following readln statements if reading from the console i.e. almost not preferring to use read for reading, "from" the console.
--- End quote ---

It isn't that it doesn't "add" an EOL but that it reads up to but excluding the ending <CR> (or <LF>), while ReadLn reads and discards it. The consequence is that after a Read there is a <CR> still in the queue which a later ReadLn will interpret as reading an empty line.

There are several ways to deal with this, among other by using the EOLn function for a conditional ReadLn, but if all one's doing is just reading a single value it's usually better to just use ReadLn().

Navigation

[0] Message Index

[#] Next page

Go to full version