title: Is there a calculation error in my program?
body: <p>Apparently there is a calculation error somewhere in my program, but I simply can’t find it.</p>
  
  <p>The only information I have as to why there is a calculation error is this following feedback given by MyProgrammingLab (A site that automatically tests code to see if it's incorrect or not). I don't know what values were entered for the annual death rate and annual birth rate to cause it. Could it be that I'm right but MyProgrammingLab is wrong? Honestly, all my own tests seem fine.</p>
  
  <p><strong>Expected Output:</strong></p>
  
  <pre><code>Year 1: 200 176
  Year 2: 176 154
  Year 3: 154 135
  Year 4: 135 118
  Year 5: 118 103
  Year 6: 103 90
  Year 7: 90 79
  </code></pre>
  
  <p><strong>Actual Output:</strong></p>
  
  <pre><code>Year 1: 200 199
  Year 2: 199 198
  Year 3: 198 197
  Year 4: 197 196
  Year 5: 196 195
  Year 6: 195 194
  Year 7: 194 193
  </code></pre>
  
  <p><strong>I built the program according to the following assignment:</strong> </p>
  
  <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 <code>Enter starting size:</code>)</li>
  <li>The annual birth rate (Prompt <code>Enter annual birth rate:</code>)</li>
  <li>The annual death rate (Prompt <code>Enter annual death rate:</code>)</li>
  <li>The number of years to display (minimum 1) (Prompt <code>Enter years to display:</code>)</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 N is the new population size, P is the previous population size, B is the birth rate, and D is the death rate. Annual birth rate and death rate are the typical number of births and deaths in a year per 1000 people, expressed as a decimal. 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><strong>My code:</strong></p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  int projectedNewSize(float population, float annualBirthRate, float annualDeathRate) {
      float annualBirthRate2 = annualBirthRate / 1000;
      float annualDeathRate2 = annualDeathRate / 1000;
  
      int newpopulation = population * (1 + annualBirthRate2) * (1 - annualDeathRate2);
      return newpopulation;
  }
  
  int main() {
  
      int populationStartingSize = 0;
      float annualBirthRate = 0;
      float annualDeathRate = 0;
      int numberOfYearsToDisplay = 0;
  
      do  {
          cout &lt;&lt; "Enter starting population size: ";
          cin &gt;&gt; populationStartingSize;
          cout &lt;&lt; "Enter annual birth rate: ";
          cin &gt;&gt; annualBirthRate;
          cout &lt;&lt; "Enter annual death rate: ";
          cin &gt;&gt; annualDeathRate;
          cout &lt;&lt; "Enter years to display: ";
          cin &gt;&gt; numberOfYearsToDisplay;
      } while (!(populationStartingSize &gt;= 2) || !(numberOfYearsToDisplay &gt;= 1));
  
      int population;
  
      for (int i = 1; i &lt;= numberOfYearsToDisplay; i++) {
          cout &lt;&lt; "Year " &lt;&lt; i &lt;&lt; ": " &lt;&lt; populationStartingSize &lt;&lt; " ";
          population = projectedNewSize(populationStartingSize, annualBirthRate, annualDeathRate);
          cout &lt;&lt; population &lt;&lt; endl;
          populationStartingSize = population;
      }
  
      system("pause");
      return 0;
  }
  </code></pre>