I need help with my code. - Programmers Heaven

Howdy, Stranger!

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

Categories

I need help with my code.

LjiffLjiff Posts: 3Member
I have an assigment where I have to make an algorithm and a program that creates a symetrical array as well as performs some functions in an order. Anyway, I thought I was doing well, I had a code example for my assignment where the program generates a random symetrical array, then arranges the array elements as a vector and performs an element search.

There is an image of the example and the result pascal should output in the attachment, so you can understand better what I am trying to say here.

The problem is, I am trying to put the example code into my program code, I have them identical, BUT pascal keeps giving me this error:

1_livabrege.pas(71,12) Error: Illegal assignment to for-loop variable "i"

I can't understant what the problem is, as the code is exactly the same as in the example, but I can't compile so I'm kind of stuck here. :/

Hope someone can enlighten me about what am I doing wrong...

P.S. Sorry if you have a hard time understanding what I am trying to say, my native language is not English, so I don't know the programming terminology. :(

Comments

  • Actor21Actor21 Posts: 35Member
    Your attachment appears to be a binary file. Do you have the source code?

  • LjiffLjiff Posts: 3Member
    Oh God, I'm such a dumbass, forgot to post the source code, took me the whole day yesterday to make something out of this assignment, I must have been dried out of brain resources at the end of it. ;D
  • LjiffLjiff Posts: 3Member
    program Lab1LivaBrege;
    uses crt;
    const n=10; m=n*(n+1) div 2;
    type matrix=array[1..n,1..n] of real;
    vector=array[1..m] of real;

    var B:Vector;
    A:Matrix;
    tkey: integer;
    option, i, j, k, X :integer;
    go_on: boolean;

    label MENU, AUTHOR, MASAPSTR, EXPR;



    BEGIN
    ClrScr;

    MENU:

    WriteLn ('Laboratorijas darbs Nr.1 kursaa Datu Strukturas.');
    WriteLn ('Ludzu izvelies kadu no zemak pieejamajam opcijam!');
    WriteLn;
    WriteLn('Raksti "1" ja velies izvadit informaciju par autoru un variantu.');
    WriteLn('Raksti "2" ja velies apstradat masivu pec varianta nosacijumiem.');
    WriteLn('Raksti "3" ja velies beigt darbu.');
    WriteLn;
    Write('Tu izvelies ');
    Read(option);
    Writeln;
    Writeln;

    CASE (option) of
    1:begin goto AUTHOR; end;
    2:begin goto MASAPSTR; end;
    3:begin writeln('Paldies!'); goto EXPR; end;
    ELSE
    WriteLn('Darbiba ar numuru', option,'nav paredzeta! Ludzu megini velreiz.');
    WriteLn;
    END;
    goto MENU;


    AUTHOR:
    WriteLn('Darba autore: Liva Brege');
    WriteLn('Grupas numurs: 3.grupa');
    WriteLn('Stud.apl.nr.: 111RDB226');
    WriteLn('Varianta numurs: 7.variants');
    WriteLn('Masiva veids: Simetriskas matricas');
    WriteLn('Masiva izmers: 10x10');
    WriteLn('Elementu tips: Real');
    WriteLn('Izpildamas funkcijas: 1, 5, 2, 4a, 5');
    WriteLn;
    WriteLn;
    goto MENU;


    MASAPSTR:

    WriteLn('Tiks veikta masiva apstrade pec attieciga varianta.');
    WriteLn;

    for i:=1 to n do
    begin
    for j:=1 to n do
    A[i,j]:=0;

    Randomize;
    WriteLn('Masivs tiks generets nejaushi.');
    WriteLn;
    for i:=1 to n do
    for j:=1 to n do
    begin
    A[i,j]:=random(10);
    end;
    for i:=1 to n do
    for j:=1 to n do
    begin
    if i=j then
    begin
    B[k]:=A[i,j];
    k:=k+1;
    end;
    end;
    WriteLn;

    WriteLn('Vektors B:');
    for k:=1 to m do
    Write(B[k]:3:2);
    WriteLn;
    WriteLn;
    WriteLn('Elementa mekleshana:');
    go_on:=false;
    WriteLn;
    Writeln('Ievadi meklejamo elementu');
    ReadLn(tkey);
    for k:=1 to m do
    if B[k]=tkey then
    begin
    WriteLn(tkey,' atrodas pozicija ',k);
    go_on:=true;
    end;
    if not go_on then
    WriteLn('Neveiksmiga mekleshana, shada elementa masiva nav.');
    end;
    readkey;


    goto MENU;

    EXPR:
    ReadLn;
    end.



    P.S. Everything else works as long as the MASAPSTR function is blank, so that is the one I am having trouble with.


Sign In or Register to comment.