Math Is Fun Forum

  Discussion about math, puzzles, games and fun.   Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ -¹ ² ³ °

You are not logged in.

#1 2011-09-22 08:36:39

anonimnystefy
Real Member
From: Harlan's World
Registered: 2011-05-23
Posts: 16,049

Programming Error!!!

hi guys

i've been doing my programming homework and i got an error,but don't know where's the problem.

here's the code.it's Pascal and written in Lazarus v0.9.28.2 beta:

program Project1;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes
  { you can add units after this };

const
  k=100;

type
  niz=array[1..k] of real;
  matrica=array[1..k] of niz;

var
  a:matrica;
  n,i,j:integer;

procedure exchange(x,y:real);
var p:real;
begin
  p:=x;
  x:=y;
  y:=p;
end;

procedure QuickSort(var a:matrica;var b:niz;levi,desni,n:integer);
var
  i,j,k:integer;
  D:real;
begin
  if levi<desni then
  begin
    i:=levi;
    j:=desni;
    D:=b[desni];
    repeat
      while b[i]<D do
        i:=i+1;
      while (b[j]>=D) and (i<j) do
        j:=j-1;
      if i<j then
      begin
        exchange(b[i],b[j]);
        for k:=1 to n do
          exchange(a[i][k],a[j][k]);
      end;
    until i=j;
    exchange(b[i],b[desni]);
    QuickSort(a,b,levi,i-1,n);
    QuickSort(a,b,i+1,desni,n);
  end;
end;

procedure GrowingRows(var a:matrica;n:integer);
var
  b:niz;
  i:integer;
begin
  for i:=1 to n do
    ------------b[i]=a[i][1];------------
  QuickSort(a,b,1,n,n);
end;

begin
  write('Enter the number of rows of the square matrix: ');
  readln(n);
  for i:=1 to n do
    begin
      for j:=1 to n do
        read(a[i][j]);
      readln;
    end;
  GrowingRows(a,n);
  for i:=1 to n do
    for j:=1 to n do
      write(a[i][j]);
  readln;
end.

i have marked the line in problem and the error message says:'Error: Illegal expression' what


“Here lies the reader who will never open this book. He is forever dead.
“Taking a new step, uttering a new word, is what people fear most.” ― Fyodor Dostoyevsky, Crime and Punishment
The knowledge of some things as a function of age is a delta function.

Offline

#2 2011-09-22 12:02:37

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

Re: Programming Error!!!

Hi anonimnystefy;

Sorry, I do not remember anything about Pascal! It is right they call it Lazarus.

General Advice:

Doesn't it have a built in debugger that allows you to single step through the program? Should also have a variable pane so you can see what is happening statement by statement.


In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

#3 2011-09-22 15:18:10

John E. Franklin
Member
Registered: 2005-08-29
Posts: 3,588

Re: Programming Error!!!

Maybe put in a begin and end around the line, even though you don't need it.
Another possiblility is that you forgot the colon in front of the equal sign...

Last edited by John E. Franklin (2011-09-22 15:19:14)


igloo myrtilles fourmis

Offline

#4 2011-09-23 07:51:55

anonimnystefy
Real Member
From: Harlan's World
Registered: 2011-05-23
Posts: 16,049

Re: Programming Error!!!

hi guys

thanks,i found the problem 10 minutes after i posted.and it was what JEF said,i was missing a colon in front of the equal sign. smile


“Here lies the reader who will never open this book. He is forever dead.
“Taking a new step, uttering a new word, is what people fear most.” ― Fyodor Dostoyevsky, Crime and Punishment
The knowledge of some things as a function of age is a delta function.

Offline

Board footer

Powered by FluxBB