0
votes

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.
1
A does not look like a multidimensional array in your declaration. - pvg
@pvg could you clarify? Does a matrix not count as a multidimensional array? (Sorry, beginner here) - Lucky
'matrix' is just a name you've given the type. You've declared it as a one-dimensional array, just like your other arrays. Why do you expect A to be multidimensional while B and C are one-dimensional, with the exact same declarations? Google up 'multidimensional array in Pascal' if you are unclear on the declaration syntax. - pvg
@Lucky, how many dimensions do you think a "multidimensional array" should have? And then how many dimensions do you think A has when A is declared as A : tMatrix; and tMatrix is defined as array[tZeile] of integer? So references like A[i, j] are errors. - lurker
Thank you to both of you! I just realized something I had fundamentally gotten wrong. This clarifies a whole bunch of questions I had. The whole thing looks so obvious now... - Lucky

1 Answers

0
votes

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.