Calculating a new population
<p>In a population, the birth rate is the percentage increase of the population due to births, and the death rate is the percentage decrease of the population due to deaths. Write a program that asks for the following:</p>

<ul>
<li>The starting size of a population (minimum 2) (Prompt Enter starting size:)</li>
<li>The annual birth rate (Prompt Enter annual birth rate:)</li>
<li>The annual death rate (Prompt Enter annual death rate:)</li>
<li>The number of years to display (minimum 1) (Prompt Enter years to display:)</li>
</ul>

<p>The program should then display the starting population and the projected population at the end of each year. It should use a function that calculates and returns the projected new size of the population after a year. The formula is</p>

<pre><code>N = P(1 + B)(1 - D)
</code></pre>

<p>where <code>N</code> is the new population size, <code>P</code> is the previous population size, <code>B</code> is the birth rate, and <code>D</code> is the death rate. Annual birth rate and death rate are the typical numbers of births and deaths in a year per 1000 people, expressed as a decimal.</p>

<p>So, for example, if there are normally about 32 births and 26 deaths per 1000 people in a given population, the birth rate would be .032 and the death rate would be .026.</p>

<p>Here is my code; I am having trouble figuring out how to do the calculation.</p>

<pre><code>#include "stdafx.h"  // Defines IDE required "pre-compiled" definition files
#include &lt;iomanip&gt; 
#include &lt;iostream&gt;

using namespace std

int main ()
{
    double startPop, // To hold the starting population. 
    float   birthRate, // To hold the birth rate. 
        float deathRate; // To hold the death rate. 
    int numYears; // To hold the number of years to track population changes. 

                  // Input and validate starting population 
    cout &lt;&lt; "This program calculates population change.\n";
    cout &lt;&lt; "Enter the starting population size: ";
    cin &gt;&gt; startPop;
    while (startPop &lt; 2.0)
    {
        cout &lt;&lt; "Starting population must be 2 or more. Please re-enter: ";
        cin &gt;&gt; startPop;
    }

    // Input and validate annual birth and death rates 
    cout &lt;&lt; "Enter the annual birth rate (as % of current population): ";
    cin &gt;&gt; birthRate;
    while (birthRate &lt; 0)
    {
        cout &lt;&lt; "Birth rate percent cannot be negative. Please re-enter: ";
        cin &gt;&gt; birthRate;
    }

    birthRate = birthRate / 100; // Convert from % to decimal. 

    cout &lt;&lt; "Enter the annual death rate (as % of current population): ";
    cin &gt;&gt; deathRate;
    while (deathRate &lt; 0)
    {
        cout &lt;&lt; "Death rate percent cannot be negative. Please re-enter: ";
        cin &gt;&gt; deathRate;
    }

    deathRate = deathRate / 100; // Convert from % to decimal. 

    cout &lt;&lt; "For how many years do you wish to view population changes? ";
    cin &gt;&gt; numYears;
    while (numYears &lt; 1)
    {
        cout &lt;&lt; "Years must be one or more. Please re-enter: ";
        cin &gt;&gt; numYears;

        population = projectedNewSize(populationStartingSize, annualBirthRate, annualDeathRate);
        cout &lt;&lt; population &lt;&lt; endl;
        populationStartingSize = population;

    }

    printPopulations(startPop, birthRate, deathRate, numYears);
    return 0;
} // End of main function
</code></pre>