Can someone help me do this exercise in C ++?

The world population doubled from 3 billion in 1959 to 6 billions in 1999. Assuming that the world population doubles every 40 years, I have to prepare a flowchart to determine what the approximate year was when the population was less than 6 million. I tried, but it does not work.
closed account (E0p9LyTq)
Create a loop of a given population (for example 6 billion) and year (1999), decreasing the year by 40 each loop iteration and halving the population.

Loop terminating condition: population less than (<) 6 million.

Now show some code to demonstrate you want to learn and not have others do your homework.
http://mathworld.wolfram.com/PopulationGrowth.html

Solve the differential equation for exponential growth.
You get the result as
P(t) = Cekt, where P is the population and t is in years.

Your unknowns are C and k, but you can find them given your initial data.

P(1959) = 3,000,000,000 = Ce1959k
P(1999) = 6,000,000,000 = Ce1999k

Using the fact that the population should double every 40 years:
• Ce1999k = 2 Ce1959k
• e1999k = 2 e1959k
• ln(e1999k) = ln(2 e1959k)
• 1999k = ln(2) + 1959k
• 1999k - 1959k = ln(2)
• 40k = ln(2)
k = ln(2) / 40

Plugging back in k to one of the equations:
• 3,000,000,000 = Ce1959( ln(2) / 40 )

C = 3,000,000,000 / e48.975 ln(2)
(you can simplify this yourself, if you wish)

Now, plug k and C back into your equation, P(t) = Cekt

~ (5.42222... × 10e-6) * exp(t * ln(2) / 40 )

_____________________________________

Edit: So now that you have the equation, but you need to find time, isolate the t.

P(t) = Cekt

ln(P(t)) = ln(C) + kt

ln(P(t)) - ln(C)= kt

(ln(P(t)) - ln(C)) / k = t

(ln(6,000,000) - ln(C)) / k = t

(In real life, this would actually be a logistic equation, since the world has a carrying capacity, but we'll ignore that.)
Last edited on
@Ganado go away u scary with ur magical math!!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <stdio.h> 
#include <iostream> /* cin, cout */

int main()
{
   // create permanent storage 
    long int humanPopulation = 6000000000; // 6 bill
    int populationYear = 1999; // starting at 1999
    
   // let the user know our starting population before looping about 
    std::cout << "Current Population: " << humanPopulation << '\n'; 

    // start looping 
    while(true) {
        // once we reach that 6mill pop break; 
        if(humanPopulation < 6000000) {
            break; 
        }else{
            populationYear -= 40; // every fourty years 
            std::cout << "Halfing population:--------------\n\n"; 
            humanPopulation = humanPopulation / 2; // half the population 

            // display our new information 
            std::cout << "Year: " << populationYear << '\n'; 
            std::cout << "Population: " << humanPopulation << "\n\n";
        }
    }

    std::cout << "in year " << popluationYear << " there were less than 6million.\n"; 
    return 0;
}


Literally had to use a while loop bc the forloop was being dumb.. I hate GDB online so damn much. Either way this project is kinda dumb and unrealistic, you cant go off 40 years of data saying it doubles every 40 years because these 40 years it happened to. ?? Wheres the proof that it doubles every 40 years? Things like Laws, Economy, Is it a trend to have more children or less children these 40 years, ect. take a large effect to this equation.
Last edited on
long int humanPopulation = 6000000000; change with this:unsigned long int humanPopulation = 6000000000;
Topic archived. No new replies allowed.