Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

2Dimensional Array Error

AlexMK92AlexMK92 Posts: 1Member
Hi guys; I am new to the programming world, just beginning to study in my A Levels so hopefully this shouldn't be a problem for you guys
For my homework assignment I need to devise a 2Dimensional array to produce my school timetable. I've looked at my script many times and can't clear the error I face on line "5/28 Timetable.pas
Fatal: Syntax error, OF expected but [ found"
I tried to troubleshoot this by making my "of" uppercase but no luck; below I have attached my script:
program Arrays;

var
//Array Variables\
myArray : Array [0..5][0..4] OF String;
Counter : integer;
//Lessons Variables\
C : Computing;
I : ICT;
P : Product Design;
B : BTEC Business;
F : Free Period;
R : Registration;

///////////////Main Program\\\\\\\
begin
///////////////Mondays Lessons\\\\\\\
myArray[0][0]:='R';
myArray[0][1]:='I';
myArray[0][2]:='C';
myArray[0][3]:='F';
myArray[0][4]:='F';
myArray[0][5]:='F';
///////////////Tuesdays Lessons\\\\\\\
myArray[1][0]:='R';
myArray[1][1]:='F';
myArray[1][2]:='I';
myArray[1][3]:='F';
myArray[1][4]:='I';
myArray[1][5]:='B';
///////////////Wednesdays Lessons\\\\\\\
myArray[2][0]:='R';
myArray[2][1]:='B';
myArray[2][2]:='I';
myArray[2][3]:='C';
myArray[2][4]:='B';
myArray[2][5]:='F';
///////////////Thursdays Lessons\\\\\\\
myArray[3][0]:='R';
myArray[3][1]:='B';
myArray[3][2];='P';
myArray[3][3];='F';
myArray[3][4];='I';
myArray[3][5];='C';
///////////////Fridays Lessons\\\\\\\
myArray[4][0];='R';
myArray[4][1];='P';
myArray[4][2];='F';
myArray[4][3]:='F';
myArray[4][4]:='C';
myArray[4][5]:='B';
end.
Any response would be much appreciated, hopefully we can get to the bottom of this ...

Thanks in advance

Alex

Comments

  • salletkdsalletkd Posts: 5Member
    Im a newbie, so Im not sure but try doing this:
    myArray:Array[0..5,0..4]:of string and later on not [0][0] but [0,0].
  • DWDuckDWDuck Posts: 31Member
    : program Arrays;
    :
    : var
    : //Array Variables\
    : myArray : Array [0..5][0..4] OF String;
    : Counter : integer;
    : //Lessons Variables\
    : C : Computing;
    : I : ICT;
    : P : Product Design;
    : B : BTEC Business;
    : F : Free Period;
    : R : Registration;
    :
    : ///////////////Main Program\\\\\\\
    : begin
    : ///////////////Mondays Lessons\\\\\\\
    : myArray[0][0]:='R';
    : myArray[0][1]:='I';
    : myArray[0][2]:='C';
    : myArray[0][3]:='F';
    : myArray[0][4]:='F';
    : myArray[0][5]:='F';
    : ///////////////Tuesdays Lessons\\\\\\\
    : myArray[1][0]:='R';
    : myArray[1][1]:='F';
    : myArray[1][2]:='I';
    : myArray[1][3]:='F';
    : myArray[1][4]:='I';
    : myArray[1][5]:='B';
    : ///////////////Wednesdays Lessons\\\\\\\
    : myArray[2][0]:='R';
    : myArray[2][1]:='B';
    : myArray[2][2]:='I';
    : myArray[2][3]:='C';
    : myArray[2][4]:='B';
    : myArray[2][5]:='F';
    : ///////////////Thursdays Lessons\\\\\\\
    : myArray[3][0]:='R';
    : myArray[3][1]:='B';
    : myArray[3][2];='P';
    : myArray[3][3];='F';
    : myArray[3][4];='I';
    : myArray[3][5];='C';
    : ///////////////Fridays Lessons\\\\\\\
    : myArray[4][0];='R';
    : myArray[4][1];='P';
    : myArray[4][2];='F';
    : myArray[4][3]:='F';
    : myArray[4][4]:='C';
    : myArray[4][5]:='B';
    : end.
    : Any response would be much appreciated, hopefully we can get to the
    : bottom of this ...
    :
    : Thanks in advance
    :
    : Alex
    :

    : Im a newbie, so Im not sure but try doing this:
    : myArray:Array[0..5,0..4]:of string and later on not [0][0] but [0,0].
    :

    Good day

    Firstly you not far off :)

    Comparing your code to the array declaration I see your order of the arrays are wrong...

    Firstly if you only going to assign a character to the array dont use up all that space by defining a array of string how about an array of char much more efficient...

    Secondly when ever defining an array of string ALWAYS set the number of expected charters in this case String[1] would have been great.

    Your compiler error should have stopped

    Personally when I define an Array I do it like

    MyArray : Array[0..5,0..4] of String[1];

    vs urs

    myArray : Array [0..5][0..4] OF String;

    Syntax not wrong but mine read easier and types faster ;)

    This is your declaration

    myArray : Array [0..5][0..4] OF String;
    col row

    0..5 i assume are the periods and 0..4 are the days... now look at your code 0..5 is the first dimension (col) and 0..4 is the second dimension (row). But in your code you switch them this will ultimately also stop you compiler as the array is going beyond its definition.

    When calling a multi array whether its to allocate value or retrieve it its always Array_Name[Col][Row] or Array_Name[Col,Row];

    Another mistake you made is assigning constant string value to a variable without telling pascal you working with constants now therefore I would insert "Const" just before "//Lessons variable\"

    Basically array definition are as follows in Pascal

    Array_Name : Array[start_value..End_Value] of [variable_type]

    After these changes you should be running
    Darkwing Duck aka DWduck signing off :)
Sign In or Register to comment.