Search code examples
arraysloopslazarusprocedures

How do I fix this error:' Illegal identifier?'


I have recently attempted creating a basic caesar-cypher in pascal (using lazarus as my compiler). My aim was to set the numbers as the array and then declare all the numbers as letters so that when i run the code it should scramble or 'encrypt' the code. I am still a beginner and have been trying to overcome the first basic problems with this code. I have learnt the theory of how it works...just haven't figured out how to put it into action :( [it keeps highlighting the numbers[1] := 'a'; code and says illegal identifier?! so far this is what i have:

program Caesarcypher;
  var
    numbers : integer;
    number : array [1..26]of integer;
begin
  numbers[1] := 'a';
  numbers[2] := 'b';
  numbers[3] := 'c';
  numbers[4] := 'd';
  numbers[5] := 'e';
  numbers[6] := 'f';
  numbers[7] := 'g';
  numbers[8] := 'h';
  numbers[9] := 'i';
  numbers[10] := 'j';
  numbers[11] := 'k';
  numbers[12] := 'l';
  numbers[13] := 'm';
  numbers[14] := 'n';
  numbers[15] := 'o';
  numbers[16] := 'p';
  numbers[17] := 'q';
  numbers[18] := 'r';
  numbers[19] := 's';
  numbers[20] := 't';
  numbers[21] := 'u';
  numbers[22] := 'v';
  numbers[23] := 'w';
  numbers[24] := 'x';
  numbers[25] := 'y';
  numbers[26] := 'z';

end.

Solution

  • You have at least two mistakes.

    1. numbers is not declared by you as an array variable. It is an integer variable only. So it does not have members [1]..[n]. You can assign something like this: numbers:=64;
    2. You have declared number as an array of integer. So you are not capable to assign character values to its members. You can assign number[1]:=1;You need to declare var numbers:array [1..26] of char; or number:array [1..26] of char; if you wish to assign character to its members.