Computer Science Canada

Clac won't work

Author:  Big_Tom [ Mon Mar 22, 2004 11:12 am ]
Post subject:  Clac won't work

I've tried everything and i can't get this to work...please help.

Author:  Delos [ Mon Mar 22, 2004 12:42 pm ]
Post subject: 

1)
In your procs/fcns, since you want to alter your parameters, declare them as variable...
code:

proc a (var b : int)
b := 3
put b
end a


2)
You cannot initialize vars/parameters at their declaration within a proc. Only after...
code:

proc a (var b : int := 3)
end a
% Will not word.


3)
All fuctions must return a value:
code:

function add (var num1 : int, var num2 : int) : int
result num1 + num2
end add

If you don't know how that worked, press F10 for more syntaxial help.

4)
You cannot call a function, only umm...'reference' it (I'm not sure of the technical term here...)

code:

fcn h (var num : int) : int
result num + 1
end h

var ans : string
var number : int := 4
put "Yes or no?"
get ans
if ans = "y" then
h(number)
end if
% This will not work.
put number


code:

fcn h (var num : int) : int
result num + 1
end h

var ans : string
var number : int := 4
put "Yes or no?"
get ans
if ans = "y" then
number := h(number)
end if
% This however, will work.
put number



That's all I could find.
Update and repost, will check again.

Author:  Thuged_Out_G [ Mon Mar 22, 2004 3:52 pm ]
Post subject: 

Delos wrote:

var ans : string
var number : int := 4
put "Yes or no?"
get ans
if ans = "y" then
% number := fcn(number) %
end if
% This however, will work.
put number


the section i commented out doesnt really work Confused

isntead of "number:=fcn(number)" do it like this

put fcn(number)

where fcn is the name of your function

ex:

code:

fcn num(a:int):int
result a
end num

var b:int
put "Enter a number: "..
get b
put num(b)

Author:  Delos [ Mon Mar 22, 2004 7:52 pm ]
Post subject: 

Thanks! I was in a rush when I typed it so I put 'fcn' instead of 'h' for those 2 examples.

I editted the post, so it reads correctly now.


: