Page 1 of 1

php class not working

Posted: Thu Oct 19, 2006 3:51 pm
by Regit
I am trying to use the following class to produce the npv (Net Pressent Value) of some numbers. I am using this for a custom app for our accounting office.

Code: Select all

class npv {

	function calcNPV($rate, $values) { 
		for ($i=0;$i<=count($values);$i+=1) { 
			$npv = $values[count($values) - $i] + $npv / (1 + $rate); 
		} 
		return $npv; 
	} 

}

// using the function
$npv = new npv();
print $npv->calcNPV(0.09, array(0,30,40,50,60,70));
what am I doing wrong, or is there another way to calculate NPV?

Posted: Thu Oct 19, 2006 3:56 pm
by RobertGonzalez
Could you help us help you by stating the problem a little more clearly%AC What is not working%AC How is it not working%AC Please be specific.

Posted: Thu Oct 19, 2006 3:59 pm
by Regit
Yes sorry, All that happens is it prints

calcNPV(0.09, array(0,30,40,50,60,70)); } ?>

to the screen, it doesnt print the npv value

Posted: Thu Oct 19, 2006 4:03 pm
by Regit
We'll I figured out what I needed to do, so there is now no problem. Thx for trying to help though, i appreciate it