//Nathan Dominguez CSC5 Chapter 5, P. 296, #11
//
/*******************************************************************************
*
* Predict Population
* _____________________________________________________________________________
* This program updates the population of organisms based on starting number of
* organisms, the percent increase of population, and the amount of days given.
*
* Computation is based on the following:
* Total Population = Start Amount + Percent Increase of Population
* _____________________________________________________________________________
* INPUT
* Population : Starting number of population
* Percent Increase of Population : Increase of current population
* Days : Number of Days
*
* OUPUT
* Total Population : Total population of a given day
******************************************************************************/
#include <iostream>
using namespace std;
int main()
{
int population;
float avgIncrease;
int daysMultiply;
// Input starting population
cout << "What is the starting number of organisms? " << endl;
cin >> population; // input
// loop for population of days
while (population < 2)
{
cout << endl << "You must have a starting size of 2 or more to continue." << endl << endl;
cout << "What is the starting number of organisms?" << endl;
cin >> population; // input
}
// Input Percent Increase in Population
cout << "What is their average daily population percentage increase? " << endl;
cin >> avgIncrease; // input
// loop for percent increase of input population
while (avgIncrease < 0)
{
cout << "The average increase cannot be a negative number." << endl << endl;
cout << "What is their average daily population percentage increase? ";
cin >> avgIncrease; // input
}
// Input the amount of Days
cout << "For how many days will they multiply? ";
cin >> daysMultiply; // input
// loop for population increase each day
while (daysMultiply < 1)
{
cout << endl << "The days must be greater than or equal to 1" << endl << endl;
cout << "For how many days will they multiply? ";
cin >> daysMultiply; // INPUT
}
// Display and calculations of results for each day passed
for (int display = 1; display <= daysMultiply; display++)
{
cout << endl << "Day " << display << endl; // output
population += (population * avgIncrease); // calculation
// output
cout << "The population grew to " << population << " organisms." << endl;
}
return 0;
}