// Arup Guha
// 9/12/09
// Solution to Fall 2009 COP 3223 Program 2C: Bacteria
// Given the initial conditions for growing bacteria, this program prints out
// a chart of how many bacteria will be around each day.

#define EPSILON 0.000001

int main() {
    
    double numBacteria, growthRate;
    int initPop, numDie, numDays, i;
    
    // Get all the user information.
    printf("How many bacteria are there on day one?\n");
    scanf("%d", &initPop);
    printf("What is their growth rate?\n");
    scanf("%lf", &growthRate);
    printf("How many bacteria die each day?\n");
    scanf("%d", &numDie);
    printf("How many days will you grow the bacteria?\n");
    scanf("%d", &numDays);
    
    // Set up the number of bacteria in the beginning.
    numBacteria = initPop;

    // Print the chart header.
    printf("Day\tNumber of Bacteria\n");
    i=1;
    
    // Loop through each day of the chart.
    while (i <= numDays) {
    
        // Print out this day's information.        
        printf("%d\t%d\n", i, (int)numBacteria);
        
        // Calculate the number of bacteria for the next day.
        numBacteria = growthRate*numBacteria - numDie;
        
        // Fix this number since we can't have a negative number of bacteria.
        if (numBacteria < 0)
            numBacteria = 0;
            
        i++; // Go to the next day!
    }
    
    // Since there is some error with doubles, it's best to check with an
    // error tolerance instead of doing numBacteria > initPop.
    if (numBacteria-initPop > EPSILON)
        printf("The bacteria will grow without bound.\n");
        
    // Same reasoning here.
    else if (initPop-numBacteria > EPSILON)
        printf("The bacteria will eventually die out.\n");
        
    // We'll get here if the two numbers are within 10^-6 of one another.
    else
        printf("The bacteria will live in a steady state forever.");

    system("PAUSE");
    return 0;        
}
    
    
