Please don't be shy to post what you've tried - that includes code. We don't want to help you do your homework. We want to help you learn. And that's more important than homework! ;)
Pv = Pa (1+p)ⁿ would have been appropriate if 'p', the rate, was constant. But that's not the case since you've been given "it drops by 0.034% every year".
There surely would be a mathematical formula for this calculation, (because I know there's a similar kinematic equation and that's all I could think of as regards to the math lol) but that's out of my scope.
But most probably and if you've been taught loops (probably have) then they want you to use a looping structure. That being said using a math formula if you know how to work it out is a great idea.
Anyways on with the problem now.
You've been given:
1) Current Population: 7,7B
2) Growth Rate initially: 1.2%
3) Rate of decrease in Growth Rate: 0.034%
You need to:
1) Find population after 75 years.
2) Print 75 rows of statistics in a tabular.
3) After how many years the popular would have doubled.
Analysis:
Finding the population after one year is fairly simple. You just need to add 1.2% of 7.7B to 7.7B
(i.e population = 7'000'000'000 + ( 7'000'000'000 * ( 12 / 100 ) )
)
Finding the population after two years is a bit different because the rate changed. You need to add 1.2% decreased by 0.034%
(i.e 1.2% - 0.034 = 1.166
) of 7.7B to the new population we calculated in the last paragraph.
(i.e population = old_population + ( old_population * ( 1.2 / 100 - 0.034 / 100 ) )
)
Observation:
It's observed that in the formula, there are two variables that keep changing.
1) Old population - We can plug this from previous calculation
2) Change in the rate (reduction) - We can calculate too by subtracting 0.034 from the previous rate.
Calculations:
1) For calculating the tabular column, we make use of the observations we have discussed.
2) For finding the population after 75 years we can use the result from tabular column
3) For calculating after how many years the population would have doubled we use the same formula.
Implementation:
This problem can be solved either recursively (don't worry if you haven't learn it yet) or iteratively (this is nothing but your do-while, while and for loops).
Let's analyze how we would do it iteratively:
We loop 75 times and we use the formula that we came up with and we maintain variables inheriting values from previous iterations of the loop.
PSEUDOCODE:
Declare variables: Current_population = 7'000'000'000, Current_rate = 1.2, Rate_change = -0.034
Start loop for 75 times:
Current_population = Current_population + ( Current_population * ( Current_rate / 100 + Rate_change / 100 ) )
print: which year and Current_population,
End of loop
Display: After 75 years, the population is : Current population
// This is because the loop ends after 75 years. Therefore the value of Current_population will be
holding the population after 75 years which is precisely what we need!
|
To calculate after how many years the population would double:
Declare: Years = 0, Initial_population = 7'000'000'000
Start loop:
Year = Year+1
Current_population = Current_population + ( Current_population * ( Current_rate / 100 + Rate_change / 100 ) )
// same formula as before
if Current_population >= 2*Initial_population
BREAK OUT OF LOOP |