canadian_angel Posted June 13, 2010 Share Posted June 13, 2010 Hi I have to do a project for school that requires me to write PHP script that calculates a 15% return on an investment of $10,000. I have to Calculate the number of years required for a single $10,000 investment to reach $1,000,000 at an average annual return of $15%. I need to use a looping statement and assume that each loop is equivalent to one year. And wow I really don't know where to begin. I am new at PHP and any help at all would be so much appreciated. Thanks! Link to comment https://forums.phpfreaks.com/topic/204667-need-help-writing-php-script-for-a-school-project/ Share on other sites More sharing options...
mattal999 Posted June 13, 2010 Share Posted June 13, 2010 Well I shouldn't really tell you the answer, but I think that the code will explain itself. I think I've done the right thing by the way (add 15% a year). <?php $investment = 10000; // Set investment amount. $i = 0; // Set years to 0. while($investment < 1000000) { $investment = $investment * 1.15; // Add 15%. $i++; // Add 1 year. } echo "Number of years: ".$i; ?> Link to comment https://forums.phpfreaks.com/topic/204667-need-help-writing-php-script-for-a-school-project/#findComment-1071557 Share on other sites More sharing options...
ignace Posted June 13, 2010 Share Posted June 13, 2010 for ($investment = 10000, $return = 1.15, $years = 1, $goal = 1000000; $investment <= $goal; $investment *= $return, ++$years) { echo 'Investment: ', $investment, ' Return: ', ($investment * $return), ' Year: ', $years, "<br>\n"; } Link to comment https://forums.phpfreaks.com/topic/204667-need-help-writing-php-script-for-a-school-project/#findComment-1071572 Share on other sites More sharing options...
canadian_angel Posted June 14, 2010 Author Share Posted June 14, 2010 Thanks for the help! I really appreciate it! Link to comment https://forums.phpfreaks.com/topic/204667-need-help-writing-php-script-for-a-school-project/#findComment-1071640 Share on other sites More sharing options...
ignace Posted June 14, 2010 Share Posted June 14, 2010 Thanks for the help! I really appreciate it! I'm sure you do You appreciate us exactly 20 points. Link to comment https://forums.phpfreaks.com/topic/204667-need-help-writing-php-script-for-a-school-project/#findComment-1071752 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.