I have the following function in my program:开发者_开发百科
function Getrand(rStart,rEnd:Integer): Integer;
var
diff: Integer;
begin
diff := rEnd - rStart;
Getrand := Random(diff) + rStart;
end;
When I try to compile the program, I get this error:
Failed when compiling
Line 27: [Error] (27:9): Invalid number of parameters in script
What am I doing wrong?
Perhaps your flavour of Pascal doesn't support the traditional return value syntax. Try Result := …
instead of Getrand := …
.
you can use
Exit(Random(diff) + rStart)
instead. But keep in mind that if you do that it will exit from function after returning the value.
You need to write Getrand(Random(diff),rStart); to send variables to function
精彩评论