Script for Factoring a number

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Assured99
Forum Commoner
Posts: 81
Joined: Wed Jul 12, 2006 11:48 am
Location: California

Script for Factoring a number

Post by Assured99 »

Im trying to create a script that will Factor a Number,
here is what i have so far but i keep getting this error unexpected T_INC, expecting ')' on Line 5

Code: Select all

<?php
$num = '14' ;
$counter = '1';

function factor($num , $counter++ ){
		 "$num / $counter++";
		}
		
Factor();
?>
Can any one point me in the right direction with finishing this script???

~Assured99
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

you cannot increment the parameter in the function declaration
function factor($num , $counter++ ){
What's the next line supposed to do?
User avatar
Assured99
Forum Commoner
Posts: 81
Joined: Wed Jul 12, 2006 11:48 am
Location: California

Post by Assured99 »

Im really just trying to get it to display all the factors of a number. so im confused on where to go next.

~snapple
User avatar
Assured99
Forum Commoner
Posts: 81
Joined: Wed Jul 12, 2006 11:48 am
Location: California

Post by Assured99 »

something like this mabye????

Code: Select all

<?php
$num = '14' ;
$counter = '1';

function factor($num , $counter){
		 "$result = $num / $counter++";
		 echo "$result";
		}
		
Factor();
?>
~Snapple
User avatar
sweatje
Forum Contributor
Posts: 277
Joined: Wed Jun 29, 2005 10:04 pm
Location: Iowa, USA

Post by sweatje »

Once you get around to actually writing the logic, this blog post may help some.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

And please read http://de2.php.net/string
why all those quotes?
Post Reply