Contains the initial population, birth rate, death rate and the number of years
#include <iostream>
using namespace std;
float fum(float m, int n)
{
float t = 1;
for (int i = 1; i <= n; i++)
{
t *=1 + m;
}
return t;
}
float growthRate(float B, float D)
{
float r;
r = B - D;
return r;
}
long int estimatedPopulation(long int p, float a, float b, int n)
{
if (p < 2)
return 0;
else if (a < 0 || b < 0)
return 0;
else
return (int)p * fum(growthRate(a, b), n);
}
void main()
{
cout << "亲,请您分别输入初始人口,出生率,死亡率和年数N:";
int a, d;
float b, c;
cin >> a >> b >> c >> d;
if (a < 2||b < 0||c < 0)
cout << "程序接收负的出生率、负的死亡率和小于2的人口数量,请重新输入";
else
cout << "人口普查统计人数为:" << estimatedPopulation(a, b, c, d) << endl;
}