Recent

Author Topic: I need help with fixing my program  (Read 1274 times)

Raffyn

  • Newbie
  • Posts: 4
I need help with fixing my program
« on: May 18, 2021, 07:09:34 pm »
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  [Select][+][-]
  1. program StudentDateSort;
  2. uses crt;
  3. type person = record
  4.              d: string;
  5.              n: string;
  6.  
  7. end;
  8. type s = array[1..30] of person;
  9. var i, j, z: integer;
  10. ds: s;
  11. x: person;
  12.  
  13. begin
  14.   clrscr;
  15.   writeln('number of students');
  16.   readln(z);
  17.   for i:=1 to z do
  18.    begin
  19.      with ds[i] do
  20.       writeln('month, day');
  21.       read(d);
  22.       writeln('last name, name');
  23.       read(n);
  24.    end;
  25.  
  26.   for i:=1 to z-1 do
  27.    for j:=z downto 1 do
  28.       with ds[i] do
  29.        begin
  30.          if ds[i].d > ds[j].d then
  31.           begin
  32.           x:=ds[i];
  33.           ds[i]:=ds[j];
  34.           ds[j]:=x;
  35.           end;
  36.        end;
  37.  
  38.   clrscr;
  39.   for i:=1 to z do
  40.    with ds[i] do begin
  41.      writeln('month, day: ' ,d);
  42.      writeln('last name, name: ' ,n);
  43.     end;  
  44.   readkey;
  45.   end.
Thanks for your help.
« Last Edit: May 18, 2021, 07:13:45 pm by Raffyn »

440bx

  • Hero Member
  • *****
  • Posts: 2368
Re: I need help with fixing my program
« Reply #1 on: May 18, 2021, 07:21:11 pm »
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  [Select][+][-]
  1.   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.
FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

speter

  • Full Member
  • ***
  • Posts: 213
Re: I need help with fixing my program
« Reply #2 on: May 19, 2021, 01:48:26 am »
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.
I climbed mighty mountains, and saw that they were actually tiny foothills. :)

Laz 2.0.10 / FPC 3.2.0 / Windows 10 (64bit)

 

TinyPortal © 2005-2018