Recent

Author Topic: error in my code  (Read 1094 times)

homojavanicus

  • Newbie
  • Posts: 4
error in my code
« on: March 25, 2020, 10:51:00 am »
hi

I writing code, and I encounter some errors. I don't understand what these error means. I would be thankful to anyone who could help me solve and understand these errors. :)

these are the error codes:

Compiling trashprogram#2.pas
trashprogram#2.pas(18,32) Error: Fields cannot appear after a method or property definition, start a new visibility section first
trashprogram#2.pas(27,2) Error: Wrong number of parameters specified for call to "pangkat"
trashprogram#2.pas(18,11) Error: Found declaration: pangkat(SmallInt;SmallInt);
trashprogram#2.pas(33,45) Error: Operator is not overloaded: "untyped" + "untyped"

this is the code
Code: Pascal  [Select][+][-]
  1. program trashprogram2;
  2.  
  3.  
  4. var
  5.         siswa: array[1..2,1..1000] of shortint;
  6.         D, N,i,max,min,j : integer;
  7.         temp: longint;
  8.        
  9. function abs_(x: integer) : integer;
  10. begin
  11.         if (x < 0) then begin  
  12.                 abs_:=-1*x
  13.         end else begin
  14.                 abs_:=x;
  15.         end;
  16. end;
  17.  
  18. procedure pangkat(x,y: integer): longint;
  19. var
  20.         temp: longint;
  21.         j: shortint;
  22. begin  
  23.         temp:=1;
  24.         for j:=1 to y do begin
  25.                 temp:=temp*x;
  26.         end;
  27.         pangkat:=temp;
  28. end;
  29.  
  30. function T(i,j: integer) : longint;
  31.  
  32. begin  
  33.         T:=pangkat(abs_(siswa[1][i]-siswa[1][j]),D)+pangkat(abs_(siswa[2][i]-siswa[2][j]),D)
  34. end;
  35.  
  36. begin
  37.         readln(D,N);
  38.         for i:=1 to N do begin
  39.                 readln(siswa[1][i],siswa[2][i]);
  40.         end;
  41.         max:=T(1,2);
  42.         min:=T(1,2);
  43.         for i:=1 to N do begin
  44.                 for j:=1 to N do begin
  45.                         if (i=j) then continue;
  46.                         temp:=T(i,j);
  47.                         if(temp>max) then begin
  48.                                 max:=temp;
  49.                         end else if (temp<min) then min:=temp;
  50.                 end;
  51.         end;
  52.         writeln(min,' ', max);
  53. end.
footnote:
fpc version 3.0.4
Lazarus ver: sorry idk

Ñuño_Martínez

  • Hero Member
  • *****
  • Posts: 1186
    • Burdjia
Re: error in my code
« Reply #1 on: March 25, 2020, 11:11:21 am »
See line 18:

Code: Pascal  [Select][+][-]
  1. procedure pangkat(x,y: integer): longint;

You declared pangkat as a procedure and gave it a type, so compiler is confused: Procedures don't have types!  Reading your code I think it should be a function.
« Last Edit: March 25, 2020, 11:13:15 am by Ñuño_Martínez »
Are you interested in game programming? Join the Pascal Game Development community!
Also visit the Game Development Portal

homojavanicus

  • Newbie
  • Posts: 4
Re: error in my code
« Reply #2 on: March 27, 2020, 06:48:35 am »
thank you it worked  ;)

 

TinyPortal © 2005-2018