I need some help with a C++ problem , and thought some of you guys might know something about it.
I have to write two functions. one function that calculates the size of the population for a year. The formula is:
N = P + BP - DP
Where N is the new population size, P is the previous population size, B is the birth rate, and D is the death rate.
And another is The printPopulations function should use a loop to compute and output the population for each of the numYears years. Each iteration of the loop should call the population function to compute the change in population for the year. I only have to write the functions, the rest of the program is already written for me. here is the code I have written. I am pretty sure its not right.
double population (double pop, double birthRate, double deathRate)
{double
newpop=pop+(pop*birthRate)-(pop*deathRate);
return newpop;}
void printPopulations(double startPop, double birthRate, double deathRate, int numYears)
{ double year;
double grandTotal;
double newpop;
{for(year=1; year <= numYears; year++,newpop=startPop)
{
cout<<year<<"\t\t"<<double population(startPop,birthRate,deathRate)<<endl;
cout<<grandTotal;
}
}
Thanks for your help!
I have to write two functions. one function that calculates the size of the population for a year. The formula is:
N = P + BP - DP
Where N is the new population size, P is the previous population size, B is the birth rate, and D is the death rate.
And another is The printPopulations function should use a loop to compute and output the population for each of the numYears years. Each iteration of the loop should call the population function to compute the change in population for the year. I only have to write the functions, the rest of the program is already written for me. here is the code I have written. I am pretty sure its not right.
double population (double pop, double birthRate, double deathRate)
{double
newpop=pop+(pop*birthRate)-(pop*deathRate);
return newpop;}
void printPopulations(double startPop, double birthRate, double deathRate, int numYears)
{ double year;
double grandTotal;
double newpop;
{for(year=1; year <= numYears; year++,newpop=startPop)
{
cout<<year<<"\t\t"<<double population(startPop,birthRate,deathRate)<<endl;
cout<<grandTotal;
}
}
Thanks for your help!