Forum > Beginners

I need help with fixing my program

(1/1)

Raffyn:
Hello, I, unfortunately, have a problem again and can't fix it myself.
It only says "identifier not found" but I actually should have initialized it.

--- 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 StudentDateSort;uses crt;type person = record             d: string;             n: string; end;type s = array[1..30] of person;var i, j, z: integer;ds: s;x: person; begin  clrscr;  writeln('number of students');  readln(z);  for i:=1 to z do   begin     with ds[i] do      writeln('month, day');      read(d);      writeln('last name, name');      read(n);   end;   for i:=1 to z-1 do   for j:=z downto 1 do      with ds[i] do       begin         if ds[i].d > ds[j].d then          begin          x:=ds[i];          ds[i]:=ds[j];          ds[j]:=x;          end;       end;   clrscr;  for i:=1 to z do   with ds[i] do begin     writeln('month, day: ' ,d);     writeln('last name, name: ' ,n);    end;    readkey;  end. Thanks for your help.

440bx:
you have 3 mistakes.

On line 21 it should be "read(x.d)"  "d" is field of a record.  You need to specify the record variable which is "x".

Similarly, on line 23, it's "read(x.n)" because "n" is a field of record variable "x".

Once you correct those two problems the compiler will let you know that it cannot "write variables of that type" in line 39.  That line should read:

--- 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";}};} ---  for i:=1 to z do writeln(ds[i].d, ds[i].n);the compiler doesn't know how to write a record.  It can only write fields (provided they are of a type it knows how to write.)

HTH.

speter:
I think - based on your indenting - that you need to add a "begin" after line 19. At present the with statement on line 19 _only_ applies to line 20 (which simply writes a string constant). Also from your indenting you should add an "end" before line 24.

cheers
S.

Navigation

[0] Message Index

Go to full version