#include #include using namespace std; // Prototype for function getdata() int getData(int&, int&, double&, double&); // Prototype for function getPop() double getPop(int start, double death, double birth); // Function main int main() { // Variable declaration int years, startPop; double newPop; char x; double deathRate, birthRate; double totalPop; newPop = startPop + (birthRate * startPop) - (deathRate * startPop); // Get user input getData(startPop, years, deathRate, birthRate); // Set accumulator totalPop = 0; // Perform calculations totalPop = getPop(startPop, deathRate, birthRate); // Display and Format output cout << fixed << showpoint << setprecision(1); cout << "The population increased from " << startPop << " to " << totalPop; // Pause script cout << "Press the enter key to exit the program." << endl; cin.ignore(); cin.get(x); return 0; } int getData(int start, int year, double deaths, double births) { cout << "What is the starting population?" << endl; cin >> start; // Validate startPop while (start < 2) { cout << "The starting population may not be less than two." << endl; cout << "Please enter a new starting population." << endl; cin >> start; } cout << "For how many years will the population change?" << endl; cin >> year; // Validate years while (year < 1) { cout << "Years may not be less than one." << endl; cout << "Please try again, entering a new value for years." << endl; cin >> year; } cout << "What is the death rate? Please enter the percentage in decimal form." << endl; cin >> deaths; // Validate death rate while (deaths < 0) { cout << "The death rate may not be negative. Please enter a new death rate." << endl; cin >> deaths; } cout << "What is the birth rate? Please enter the percentage in decimal form." << endl; cin >> births; // Validate birth rate while (births < 0) { cout << "The birth rate may not be negative. Please enter a new birth rate." << endl; cin >> births; } return 0; } double getPop(int start, double death, double birth) { int years; double newPop, totalPop; for (int count = 1; count <= years; count++) { newPop = start + (start * birth) - (start * death); totalPop += newPop; } return totalPop; }