Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more

Go Back   Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more > Web Programming > PHP Development
User Name
Password

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 09-10-2006, 08:30 PM   #1 (permalink)
O~Snapple
Moderator Of The Year
 
O~Snapple's Avatar
 
Join Date: Jul 2006
Location: Cali Breeze
Posts: 716
Send a message via MSN to O~Snapple Send a message via Skype™ to O~Snapple
Default Number Factoring PHP Script HELP!!!

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
PHP Code:
<?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???
I think im moving in the right direction.

~Snapple
__________________
The Real Truth
Epademik Emcee Esq. New Album The 3rd Finger is in Stores Now!
Snap Marketing Management and Consulting
O~Snapple is offline   Reply With Quote
Sponsored Links
Old 09-11-2006, 03:58 AM   #2 (permalink)
moriakaice
Junior Member
 
Join Date: Aug 2006
Posts: 29
Default Re: Number Factoring PHP Script HELP!!!

PHP Code:
<?php  
$num 
'14' ;  
$counter '1';  

function 
factor($num$counter '1'
{  
    ++
$counter
    if ( (
$num $counter == 0) && ($num $counter) ) 
    { 
    echo 
$num.' can be divided by '.$counter.'<br>'
    
factor($num$counter);
    } 
    elseif( (
$num $counter != 0) && ($num $counter) ) 
    { 
    
factor($num$counter);
    } 
    else 
    { 
    echo 
$num.' can be divided by '.$num.'<br><br>'
    } 
}  
          
factor($num$counter); 

factor(17); 

factor(38,5);

factor(198,1);
?>

Last edited by moriakaice : 09-11-2006 at 04:14 AM.
moriakaice is offline   Reply With Quote
Old 09-11-2006, 06:15 AM   #3 (permalink)
Itsacon
Junior Member
 
Itsacon's Avatar
 
Join Date: Sep 2006
Location: Sector ZZ9 Plural Z Alpha
Posts: 34
Send a message via ICQ to Itsacon
Default Re: Number Factoring PHP Script HELP!!!

Aside from the functional errors moriakaice, pointed out, a simple explanation of the error you're getting:
PHP Code:
function factor($num $counter++ ) 
is not allowed.
In the same way that
PHP Code:
function factor($num $counter=$someothervar
wouldn't be allowed.
default values for function parameters need to be constant, they will NOT be evaluated at runtime.

Have a look at the PHP manual entry on function arguments for more details.

A little addition to moriakaice's script: I'd add a check after each increment operation to make sure $counter isn't zero. Calling the function with factor($num, -1); will terminate the script in a quick and dirty way...
__________________
"The biggest problem encountered while trying to design a system that was completely foolproof, was, that people tended to underestimate the ingenuity of complete fools."
---Douglas Adams
Itsacon is offline   Reply With Quote
Old 09-11-2006, 10:31 AM   #4 (permalink)
moriakaice
Junior Member
 
Join Date: Aug 2006
Posts: 29
Default Re: Number Factoring PHP Script HELP!!!

Yup, we can add:
PHP Code:
if ($counter 2
{
    
$counter 2;
}

$counter floor($counter); 
after ++counter;

Of course, you can put the floor into some checking, so it won't be executed each time; it's up to you. Same with $counter checking - if you'll be factorising numbers by yourself, you won't provide it with incorrect arguments, however, when making it public, Itsacon is right, be careful about varibles.
moriakaice is offline   Reply With Quote
Old 09-11-2006, 10:11 PM   #5 (permalink)
macboy9000
Junior Member
 
Join Date: Sep 2006
Posts: 38
Default Re: Number Factoring PHP Script HELP!!!

i seem to be missing something. where is the factored number going to go? the script seems to do the job, then dead end? don't you want it to echo the output somewhere?
macboy9000 is offline   Reply With Quote
Old 10-01-2006, 07:53 PM   #6 (permalink)
O~Snapple
Moderator Of The Year
 
O~Snapple's Avatar
 
Join Date: Jul 2006
Location: Cali Breeze
Posts: 716
Send a message via MSN to O~Snapple Send a message via Skype™ to O~Snapple
Default Re: Number Factoring PHP Script HELP!!!

Sorry for being so late to the game, yeah i need it to echo the results, Also i dont want the numbers to duplicate so im going to play with this. I tend to learn better by disecting the code to see what does what. now here is another question.

PHP Code:
<?php
Function factor (This is the Function)
{
But what does the second set of brackets imply???}
?>
__________________
The Real Truth
Epademik Emcee Esq. New Album The 3rd Finger is in Stores Now!
Snap Marketing Management and Consulting
O~Snapple is offline   Reply With Quote
Old 10-02-2006, 02:24 AM   #7 (permalink)
moriakaice
Junior Member
 
Join Date: Aug 2006
Posts: 29
Default Re: Number Factoring PHP Script HELP!!!

PHP Code:
<?php

function ThisIsFunctionName ($thisIsFunctionStartingParameter1$thisIsFunctionStartingParameter2)
//here the function instructions start

//here the function does what it does

// here the function instructions end
In my function, the numbers were not duplicated, so I don't see reason to edit anything.
__________________
Lustrzany Kontynent || Paznokcie || Tipsy || Galeria fryzur
moriakaice is offline   Reply With Quote
Old 10-02-2006, 02:16 PM   #8 (permalink)
O~Snapple
Moderator Of The Year
 
O~Snapple's Avatar
 
Join Date: Jul 2006
Location: Cali Breeze
Posts: 716
Send a message via MSN to O~Snapple Send a message via Skype™ to O~Snapple
Default Re: Number Factoring PHP Script HELP!!!

Mori,

Thanks now can the Paramaters be blank???

like...
PHP Code:
<?php

Function factor()
//yadda yadda yadda 
//Yadda yadda yadda 
}
?
__________________
The Real Truth
Epademik Emcee Esq. New Album The 3rd Finger is in Stores Now!
Snap Marketing Management and Consulting
O~Snapple is offline   Reply With Quote
Old 10-03-2006, 02:16 AM   #9 (permalink)
moriakaice
Junior Member
 
Join Date: Aug 2006
Posts: 29
Default Re: Number Factoring PHP Script HELP!!!

Yup, no problems.

It can be
PHP Code:
<?php

function OurFunction1 ()
{
echo 
'Working';
}

function 
OurFunction2($text 'Default value of TEXT if not provided')
{
echo 
$text;
}

function 
OurFunction3 ($text1$text2 'Default again')
{
echo 
$text1.'<br>'.$text2;
}

function 
Break2Lines ()
{
echo 
'<br><br>';
}

OurFunction1();
Break2Lines();
OurFunction2();
Break2Lines();
OurFunction2('Break, I need break...');
Break2Lines();
OurFunction3('Smexy');
Break2Lines();
OurFunction3('Smexy''... Not really');

?>

Try these
__________________
Lustrzany Kontynent || Paznokcie || Tipsy || Galeria fryzur
moriakaice is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Points Per Thread View: 1.00
Points Per Thread: 11.00
Points Per Reply: 5.00



» Sponsors

» Links

» Affiliates
Web Hosting
Online Backup Reviews
Marketing Find
Merchant Select
SiteMap Builder
Host Compare
Dedicated Servers

» Links

» Sports Network
Paintball Forum
Football Forum
Hockey Forum
Golf Forum
Boxing Forum
Lacrosse Forum
Baseball Forum
SnowBoarding Forum
Soccer Forum
MMA Forum


All times are GMT -4. The time now is 08:56 AM.



LinkBacks Enabled by vBSEO 3.0.0 RC8
Webmaster Forums