# My Recursive Function

## Recommended Posts

I have made a recursive function -

`function croncount ( \$sec, \$count ) {	if ( \$sec > 299 ) {			\$count = \$count + 1;				\$sofar =  \$count * 300;				\$poo = \$sec - \$sofar;				croncount ( \$poo, \$count );		} else {			return "\$count";		}}`

It is supposed to work out how many lots of 300 there are in the number (\$sec).But when I print out this function, nothing is returned?What have I done wrong?I set \$count to "0" when calling the function, so it starts from "0".EDIT: Nevermind just found the problem, I wasn't returning the function in the first IF bit.

##### Share on other sites

Would it not be easier to divide by 300 and find the integer value:\$number = intval (\$sec/300);\$number will then give you the number of complete 300s within the value of \$sec.

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account