|
-
July 23rd, 2009, 06:45 PM
#1
could someone help me fix this?
the initial population is not working for some reason. could anyone help me fix it as this is a dire situation for finishing this program assignment. I would appreciate it.
Code:
#include<iostream>
#include<cmath>
//Source of Verhulst Formula: http://www.unc.edu/depts/cmse/math/Verhulst.html
using namespace std;
double population, growth_Percent, growth_rate, loss_Percent, h, carry_capacity, year, temp; //Declaration of global varaibles
double expectedpopulation (double years); //prototype expectedpopulation
int main()
{
cout << "The verhulst formula program" << endl;
cout << "Please provide the initial population : ";
while( !( cin >> population )|| population < 0 )
{
cin.clear();
cin.ignore(std::numeric_limits<std::streamsize>::max(),'\n');//Professor J. Epstein did this part when I was observing with Devin
cout << "Please provide the initial population : ";
}
cout << "Please provide the population growth rate percentage : ";
while( !( cin >> growth_rate )|| growth_rate < 0 )
{
cin.clear();
cin.ignore(std::numeric_limits<std::streamsize>::max(),'\n');
cout << "Please provide the population growth rate percentage : ";
growth_rate = growth_rate/100; // percent converted to a decimal
}
cout << "Please provide the population loss rate percentage : ";
while(!(cin >> h) ||h < 0 )
{
cin.clear();
cin.ignore(std::numeric_limits<std::streamsize>::max(),'\n');
cout << "Please provide the population loss rate percentage : ";
h = h/100; //percent converted to a decimal
}
cout << "Please provide the population capacity : ";
while(!(cin >> carry_capacity) || carry_capacity < 0 )
{
cin.clear();
cin.ignore(std::numeric_limits<std::streamsize>::max(),'\n');
cout << "Please provide the population capacity : ";
}
cout << "Please provide the number of year(s) after the initial population to predict the expected population : ";
while(!(cin >> year )|| year < 0 )
{
cin.clear();
cin.ignore(std::numeric_limits<std::streamsize>::max(),'\n');
cout << "Please provide the number of year(s) after the initial population to predict the expected population : ";
}
cout << "The expected population " << year << " year(s) from the initial population is " << expectedpopulation(year) << endl;
system("pause");
return 0;
}
double expectedpopulation (double years)// this is the recursion function
{
if (years == 0)
return population;
else
double temp = expectedpopulation(years-1);
return (1 + growth_rate - h)*temp - growth_rate * pow( temp, 2 ) / carry_capacity;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|