Feb-07-2021, 04:04 PM
Be smart with you calculations. Do you need to know the increase per week or do you just need to know the total after 5 weeks?
start = 150
week 1 = start * 1.15
week 2 = week 1 * 1.15
week 3 = week 2 * 1.15
week 4 = week 3 * 1.15
week 5 = week 4 * 1.15
Or
week 5 = 150 * 1.15 * 1.15 * 1.15 * 1.15 * 1.15
week 5 = 150 * 1.15^5
You may want to correct the result to eliminate partial apples.
This can be made to work for the general case when you specify the starting value, the increase rate and the number of increase periods.
The first step in writing code is solving the problem. Once you solve the problem it is fairly simple to translate the solution to code.
start = 150
week 1 = start * 1.15
week 2 = week 1 * 1.15
week 3 = week 2 * 1.15
week 4 = week 3 * 1.15
week 5 = week 4 * 1.15
Or
week 5 = 150 * 1.15 * 1.15 * 1.15 * 1.15 * 1.15
week 5 = 150 * 1.15^5
You may want to correct the result to eliminate partial apples.
This can be made to work for the general case when you specify the starting value, the increase rate and the number of increase periods.
The first step in writing code is solving the problem. Once you solve the problem it is fairly simple to translate the solution to code.