CodyT07
|
Little php helpBeen a while since I programmed in php but I heard the idiots that run our school servers might install php, considering they got hacked cause they couldn't install asp So in hopes of being ahead of the pack in the web design class I been doing a little php reading and testing. So far I did a simple calculator but I been trying to make it a little more advance, one of the problems is doing 'powers'
E.g 3 ^10 which is 3*3*3*3*3*3*3*3*3*3*3*3.
Problem is I have no clue how to program that , php doesn't know what to do with ^ My guess was a loop but I keep ending with the answer of "0". Anyone know of a direction I should try to do it correct?
If you are noosy here is my calculator so far
I did set bad numbers for the celsius to Fahr but I will work on that later.
Yes I did all that by myself.
|
Andrew(AP)
|
http://huntingsphere.exofire.net/calculator.php
Well i have no idea about the powers but I was bored and did a little remodeling.
Good luck with your calculator though.
|
CodyT07
|
After I got the core code down I would of made it look better. Big thing was to fix the "=" showing up for no reason, could add it in the final echo statement.
but that does look good!
Maybe I can make really advance, doubt much more advance but it is a start.
|
CodyT07
|
| Code: | case "^";
function powers ($num, $power)
{
// in case garbage is passed in.
if(!is_numeric($num) || !is_numeric($power))
return 0;
if($num<=0 || $power<=0)
return 0;
$result = 1;
for($cnt=1; $cnt<=$power; $cnt++)
{
$result = $result * $num;
}
return $result;
}
$output = powers($num1,$num2);
echo($output);
} |
Seems to be it...
Going to try other mathematical equations too.
|
interlog
|
use:
pow(base, power)
e.g
echo pow(3,10);
Mark
|
CodyT07
|
| interlog wrote: | use:
pow(base, power)
e.g
echo pow(3,10);
Mark  |
*slaps self*. Thanks for that.
|
|
|