how to make this function??
Author 
Message 
appling





Sponsor Sponsor



shorthair

Posted: Tue Feb 24, 2004 3:20 pm Post subject: (No subject) 


Function Hello
*
*
*
*
end Hello
Hello 





appling

Posted: Tue Feb 24, 2004 3:29 pm Post subject: (No subject) 


i dont know how to call the function, so can u write the code and let me have a look? 





recneps

Posted: Tue Feb 24, 2004 3:49 pm Post subject: (No subject) 


Functions are simple.
code:  procedure ProcedureNameHere
%Code here...
var x, y : int
var prime : array 1 .. 7 of int := init (2, 3, 5, 7, 11, 13, 15)
var a : array 1 .. 7 of int
get x
for i : 1 .. 7
y := 0
loop
if x mod prime (i) = 0 then
x := x div prime (i)
y := y + 1
else
exit
end if
end loop
a (i) := y
end for
for k : 1 .. 7
put a (k)
end for
% end code.
end ProcedureNameHere
% then to call, just type the proc name.
ProcedureNameHere

Simple Simple. 





appling

Posted: Tue Feb 24, 2004 4:02 pm Post subject: (No subject) 


sorry, the teacher told me just use the function not the procedure.so...
thank u all the same 





naoki

Posted: Tue Feb 24, 2004 4:55 pm Post subject: (No subject) 


The above poster is wrong, that's actually a procedure, not a function
A function goes
code: 
function whateverthename (place parameters here) : whatever returning value (can be boolean, integer, string, real)
put code here
should end in
result whatever returning value (i.e. result true, result num ... )
end whateverthename

calling it is different than a procedure. You can't just run it normally. For example, if it returned a boolean answer, you would go
code: 
if whatever the name (parameters) = true then







appling

Posted: Tue Feb 24, 2004 5:13 pm Post subject: (No subject) 


i tried this
code:  function KKK (var x : int) : array 1 .. 7 of int
var prime : array 1 .. 7 of int := init (2, 3, 5, 7, 11, 13, 15)
var a : array 1 .. 7 of int
var y : int
for i : 1 .. 7
y := 0
loop
if x mod prime (i) = 0 then
x := x div prime (i)
y := y + 1
else
exit
end if
end loop
a (i) := y
end for
end KKK
var X : int
get X
put KKK (X) 
but turing said "illegal put item" ???
i dont know where i am wrong 





naoki

Posted: Tue Feb 24, 2004 5:45 pm Post subject: (No subject) 


i dunno, I don't really feel like running it but I'm guessing that Turing won't let you have a whole ARRAY as your returning value. I mean, think about it: Turing has NO idea how you want to output or result an array. Do you want to add/catenate the values? Do you want them output on the same line or seperate lines? Ambiguous cases aren't Turing's specialty
also, if you look in your function you never declared "result" and then whatever you wanted. You just put exit. That means that it's supposed to return something, but you're not telling it what.
Change the resulting value, and make sure you have one in your program. If you want to return an array value, that could work, but not the entire array 





Sponsor Sponsor



shorthair

Posted: Tue Feb 24, 2004 5:49 pm Post subject: (No subject) 


you need to result somthing , 





appling

Posted: Tue Feb 24, 2004 5:50 pm Post subject: (No subject) 


what i need to do if i want the whole array(array a) as my result?
and how to call it? 





Thuged_Out_G

Posted: Tue Feb 24, 2004 10:38 pm Post subject: (No subject) 


your program doesnt output anything, it just does some variable changes if some conditions are true, so it would make more sense to make the program a procedure with parameters instead of a function. 





recneps

Posted: Wed Feb 25, 2004 6:12 pm Post subject: (No subject) 


oops! haha, sorry there, i kinda started on functions and then got interrupted, and kinda changed to procedure :\ 





appling






