When I run it,it appear error 88:'')'' is expected in A[L]:=sort;.
I think it is no need to add '')''.
What error 88 mean:?:

const
  max = 100;
var
  A: array[1..max] of real;

function Sort(L, R:integer):real;
begin

for L:= L to R-1 do begin
  if A[L]<A[L+1] then begin
  sort:=A[L+1];
  A[L+1]:=A[L];
  A[L]:=sort;
  end;
end;

end;

var
  I, N, L, R: integer;

{ Main Program }
begin
  readln(N);
  for I := 1 to N do
    read(A[I]);
  readln;
  readln(L, R);
  sort(L, R);

  for I := 1 to N - 1 do
    write(A[I]:0:7, ' ');
  writeln(A[N]:0:7)
end.

Edited 6 Years Ago by Nick Evan: added code tags

Hi yozuca,

I think the problem is that you try to assign to that real entity(a[L]) the result of the function. "sort" function has two parameters, so the correct assignment would be :

a[L] := sort(FirstParameter, SecondParameter); here you call the function.
I suggest to use a local variable of type real.

function Sort(L, R:integer):real;
var
   Temp : real;
begin

for L:= L to R-1 do 
  if A[L]<A[L+1] then begin
  Temp:=A[L+1];
  A[L+1]:=A[L];
 A[L]:=Temp;
  end;

sort := 1; //another suggestion is to use a procedure instead of a function. A function is usefull when you have to return a value.

end;

Ionut

First , error 88 is that the compiler waits for the (
and second I fixed your program.

program solution01;

const max = 100;

var A: array[1..max] of real;

function Sort(L, R:integer):real;
begin
     for L:= L to R-1 do begin
         if A[L]<A[L+1] then begin
            sort:=A[L+1];
            A[L+1]:=A[L];
            sort:=A[L];   (*A[L]:=sort; wrong reference!Look at mine!*)
         end;
     end;
end; (*of Sort*)

var I, N, L, R: integer;

{ Main Program }
begin
     readln(N);
     for I := 1 to N do read(A[I]);
     readln;
     readln(L, R);
     sort(L, R);
     for I := 1 to N - 1 do write(A[I]:0:7, ' ');
     writeln(A[N]:0:7);
end.
(*fixed by FlamingClaw.2010.04.13.Hungary*)

Edited 6 Years Ago by FlamingClaw: n/a

To Add to what FlamingClaw said
Your function needs to be refined still further. Understand the difference between a function and a procedure. You have not used the result of the function in the application but seem to have tried to use the result in the function itself.

procedure Sort(L, R:integer); //--> use procedure as no result is returned
Var Temp:Real;
       aCount:Integer;
       HasSwapped :Boolean;
begin
    Repeat
       HasSwapped:=False;
       for aCount:= L to R-1 do 
       begin
           if A[aCount]<A[aCount+1] then 
           begin
              Temp:=A[aCount+1];
              A[aCount+1]:=A[aCount]; 
              A[aCount]:=Temp;
              HasSwapped:=True;
           end;
       end;
    Until HasSwapped=False;
(* Search for bubble sort for a more efficient sorting algorithm more suited to array sorting  *)
end; (*of Sort*)

Hope this helps
Regards Cao

This question has already been answered. Start a new discussion instead.