Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4098
Number of posts: 14002

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
I need help with my code. Posted by Ljiff on 6 Mar 2012 at 11:57 AM
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. :(
Attachment: 111.rar (136235 Bytes | downloaded 49 times)
Report
Re: I need help with my code. Posted by Actor21 on 6 Mar 2012 at 6:56 PM
Your attachment appears to be a binary file. Do you have the source code?

Report
Re: I need help with my code. Posted by Ljiff on 6 Mar 2012 at 8:37 PM
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
Report
Re: I need help with my code. Posted by Ljiff on 6 Mar 2012 at 8:40 PM
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
A[i,j]:=A[j,i];
end;
WriteLn('Masivs A:');
for i:=1 to n do
begin
for j:=1 to n do
Write(A[i,j]:3:2);
WriteLn;
end;

k:=1;
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.





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.