newbie: Illegal type expression

Monkey Forums/Monkey Programming/newbie: Illegal type expression

vmars316(Posted 2013) [#1]
Below is my 1st monkey program:
If I run with the parameter "Strict" ,
I get this error:
Function Factorial:Int(n)
Illegal type expression

If I don'e specify "Strict"
I get this error:
SyntaxError - Unexpected token 'function'
Function Main:Int()

Pls, what am I doing wrong ?
Also , If you see other errors , pls show me the right way ...Thanks
' enable strict mode
' Strict 
Global n:Int 
Global FactIn:Int = 4  
Global FactOut:Int = 0  
Global ItNum:Int = 0

Function Factorial:Int(n) 
	Print ("Iteration " + (ItNum + 1) + "  n= " + n)
       If (n <= 1)  
		Return 1  
	Else 
        	Return Factorial(n-1) * n  
End 
  
' the entry point for monkey
Function Main:Int()
	n = FactIn 	
       FactOut = Factorial(n)
	Print("Factorial of " + FactIn + " is " + FactOut)	  
       Return 0
End



DruggedBunny(Posted 2013) [#2]
You need to specify the parameter type:

Function Factorial:Int(n:Int)


[EDIT] Oh, and you need an EndIf at the end of every If block.

Also, it's not a good idea to have a global called 'n' and a function parameter called 'n'.


Midimaster(Posted 2013) [#3]
you forgot an "Endif"


vmars316(Posted 2013) [#4]
Thanks All.