I'm trying to do perform a series of calculations based on some initial user input, but am, frankly, a little baffled and would really appreciate some pointers, please?!
What I'm trying to do, is take some user data (initial level, weekly increase and frequency) and then perform a set number of calculations based on the frequency, ie. 52 calculations, one for each week.
This might be a bit tricky to explain, but at the start of the loop, week 1 of $frequency, the initial_level is (for example) 11, but this changes as a result of the calculation. I want to pass the new result ($calculation) to the next calculation.
So, for example, if in week 1, the level is 11, it might change to 10.1 in week 2, 9.8 in week 3 and so on. Basically, I'm trying to predict the level after 52 weeks, based on 52 repetitions of the calculation.
// Initial level from user
$initial_level = "11";
$weekly_increase = "4";
$frequency = "52"; // weekly
// Set up loop
$actions = 1;
$calculation = $initial_level;
while ($actions <= $frequency) {
// Perform calculation
$calculation = ( ( .25 * $calculation) + $weekly_increase) / .25;
// Debugging
print("$actions : $calculation = ( ( .25 * $calculation) + $weekly_increase) / .25<br/>");
// Increment loop for next water change
$actions++;
}
However, while I can get the loop to run 52 times, I can't get it to pass the result of the calculation to the next calculation (ie. the result of week 1 ($calculation) becomes the $calculation value used in the calculation for week 2.
Apologies if I've not explained this very clearly. If I actually explained the calculation, it would probably only confuse you even more!
Any input would be extremely gratefully received.
Many thanks!