0
votes

I got this error when trying to compile. pascal error image

left side cannot be assign to, ./number 21,22 in pastebin

here is my code

Program urut;
Uses Wincrt;
Const N =  5;
   data:  Array [1..N] Of Integer =  (2,4,5,3,1);
Var
   j,k,temp :  Integer;
Begin
 Clrscr;
Writeln ('Data sebelum diurutkan');
For j:=1 To N Do
   Begin
     Writeln('data[' ,j, ']= ',data [j]);
  End;
For j:=1 To N-1 Do
  Begin
     For k :=N Downto j+1 Do
        Begin
           If data[k] < data[k-1] Then
              Begin
                 temp := data[k];
                 data[k] := data[k-1]; //left side cannot be assigned to
                 data[k-1] := temp; //left side cannot be assigned to
              End;
        End;
  End;
Writeln;
Writeln ('Data setelah diurutkan ');
For j:=1 To N Do
   Begin
      Writeln ('data[' ,j, '] = ',data[j]);
   End;
 Writeln;
 End.  

sorry for uncorrectly pattern post , thank you so much.

1
Array data[] is declared as a const. Therefore it can't be changed. - Tom Brunberg
Thank you so much, my promblem is solved. How to close this question? - user10032474
You can "close" the question by "accepting" the answer see here. You can accept your own answer to your own question, but it will not take effect until 48 hours later, and you will not be rewarded reputations. I suggest you visit the help center and read especially about asking and answering. Cheers - Tom Brunberg

1 Answers

0
votes

Like tom Tom Brunberg says, my array is const, it can't be changed. Therefore I need to remove that const.

So it should be

data: Array [1..5] Of Integer = (value);

without const, and put it under var with another variable