Lucky Lucky - 8 months ago 231
Pascal Question

Pascal error: illegal qualifier

The code below is supposed to create a 3x4 matrix and and print the sum of all numbers each row. However, upon compiling it, I keep getting the following errors:

jdoodle.pas(26,25) Error: Illegal qualifier
jdoodle.pas(33,32) Error: Illegal qualifier
jdoodle.pas(41,32) Error: Illegal qualifier
jdoodle.pas(48,24) Error: Illegal qualifier
jdoodle.pas(56,4) Fatal: There were 4 errors compiling module, stopping
Fatal: Compilation aborted.


The lines in question are:

line 26: readln (A[i, j]);
line 33: B[i] := B[i] + A[i, j]
line 41: C[J] := C [J] + A[i,j]
line 48: write (A[i, j]:5);


Could anyone clarify this for me please? The main problem is, that I don't really know what that error code means. I have noticed that 'A[i,j]' is in all lines that are mentioned in the errors, but I just can't find out what is wrong with it.Any help would be greatly appreciated!

And here is my complete code:

Program Matrix (input, output);

const
ZEILENMAX = 3;
SPALTENMAX = 4;
type
tZeile = 1..ZEILENMAX;
tSpalte = 1..SPALTENMAX;
tMatrix = array[tZeile] of integer;
tZeilensumme = array [tZeile] of integer;
tSpaltensumme = array [tSpalte] of integer;

var
A : tMatrix;
B : tZeilensumme;
C : tSpaltensumme;
i : tZeile;
j : tSpalte;

begin


for i := 1 to ZEILENMAX do
for j := 1 to SPALTENMAX do
readln (A[i, j]);


for i := 1 to ZEILENMAX do
begin
B[i] := 0;
for j := 1 to SPALTENMAX do
B[i] := B[i] + A[i, j]
end;


for j := 1 to SPALTENMAX do
begin
C[j] := 0;
for i := 1 to Zeilenmax do
C[J] := C [J] + A[i,j]
end;

writeln;
for i := 1 to ZEILENMAX do
begin
for j := 1 to SPALTENMAX do
write (A[i, j]:5);
writeln (B[i]:10)
end;

writeln;
for j:= 1 to SPALTENMAX do
write (C[j]:5);
writeln
end.

Answer Source

Let us transcript the following piece of code:

const
  ZEILENMAX = 3;
type
  tZeile = 1..ZEILENMAX;
  tMatrix = array[tZeile] of integer;
var
   A : tMatrix;

it is equal to:

type
  tZeile = 1..3;
  tMatrix = array[tZeile] of integer;
var
   A : tMatrix;

and this is similar to:

type
  tMatrix = array[1..3] of integer;
var
   A : tMatrix;

Members of array A can be accessed by a single index: A[1] := 0; but not A[1,1] := 1 or alike.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download