Once again, I am asking everybody to help me out with my simulation. And once again, I will fill everybody in if someone hasn't looked over my previous posts. I am making a simulation on an ecosystem, with 3 animals. Each animal has a ?/? chance of being created, and a ?/? of being destroyed. Here is the code so far:

Here is the big problem. At the minute, the values are being written to a log file. The project I'm doing involves taking the values, and converting them into graphs, and then to analyze them, etc. Imagine taking 29,000+ values, and in someway trying to count, or use Find to count the number of Created or Destroyed animals. How do I do it, so that it does write the values to the log file, but it also displays the number of created and destroyed animals at the end of the program?Code:#include <stdio.h> #include <stdlib.h> #include <time.h> int main () { float numerator; float denominator; int interval; int created = 0; int total = 0; int element; int end; int duration; int sample; FILE *fp; srand (time(0)); printf("Welcome to Eco-Sim!\n"); printf("Version 1.00\n"); printf("By Jack Olszewski\n"); printf("\n"); printf ("Time (1 = 1 Year):"); scanf ("%d",&end); printf("\n\n"); printf("Plant:\n"); printf("\n"); printf ("Enter the Numerator for Creation: "); scanf ("%f", &numerator); printf ("Enter the Denominator for Creation: "); scanf ("%f", &denominator); printf ("\nProbability Of Creation Is: %f\n", (numerator/denominator)/2); interval = (int)((numerator/denominator)/2*RAND_MAX); if ((fp = fopen ("plantcreation.txt", "w")) == NULL) { printf ("\nError: Unable to open file"); return 1; } duration = end + time (0); while ( time (0) < duration ) { sample = rand (); fprintf(fp,"Plant Creation Log"); fprintf (fp, "Day: %d\t", total); if (sample < interval) { fprintf (fp, "Created\n\n"); created++; } else fprintf (fp, "Not Created\n\n"); total++; } printf("\n"); printf ("Enter the Numerator for Destruction: "); scanf ("%f", &numerator); printf ("Enter the Denominator for Destruction: "); scanf ("%f", &denominator); printf ("\nProbability Of Destruction Is: %f\n\n", (numerator/denominator)/2); interval = (int)((numerator/denominator)/2*RAND_MAX); if ((fp = fopen ("plantdestruction.txt", "w")) == NULL) { printf ("\nError: Unable to open file"); return 1; } duration = end + time (0); while ( time (0) < duration ) { sample = rand (); fprintf (fp,"Plant Destruction Log"); fprintf (fp, "Day: %d\t", total); if (sample < interval) { fprintf (fp, "Destroyed\n\n"); created++; } else fprintf (fp, "Not Destroyed\n\n"); total++; } printf("Herbivore:"); printf("\n\n"); printf ("Enter the Numerator for Creation: "); scanf ("%f", &numerator); printf ("Enter the Denominator for Creation: "); scanf ("%f", &denominator); printf ("\nProbability Of Creation Is: %f\n\n", (numerator/denominator)/2); interval = (int)((numerator/denominator)/2*RAND_MAX); if ((fp = fopen ("herbivorecreation.txt", "w")) == NULL) { printf ("\nError: Unable to open file"); return 1; } duration = end + time (0); while ( time (0) < duration ) { sample = rand (); fprintf (fp,"Herbivore Creation Log"); fprintf (fp, "Day: %d\t", total); if (sample < interval) { fprintf (fp, "Created\n\n"); created++; } else fprintf (fp, "Not Created\n\n"); total++; } printf ("Enter the Numerator for Destruction: "); scanf ("%f", &numerator); printf ("Enter the Denominator for Destruction: "); scanf ("%f", &denominator); printf ("\nProbability Of Destruction Is: %f\n\n", (numerator/denominator)/2); interval = (int)((numerator/denominator)/2*RAND_MAX); if ((fp = fopen ("herbivoredestruction.txt", "w")) == NULL) { printf ("\nError: Unable to open file"); return 1; } duration = end + time (0); while ( time (0) < duration ) { sample = rand (); fprintf (fp,"Herbivore Destruction Log"); fprintf (fp, "Day: %d\t", total); if (sample < interval) { fprintf (fp, "Destroyed\n\n"); created++; } else fprintf (fp, "Not Destroyed\n\n"); total++; } printf("Carnivore:"); printf("\n\n"); printf("Enter the Numerator for Creation:"); scanf("%f", &numerator); printf("Enter the Denominator for Creation:"); scanf("%f", &denominator); printf("\nProbability Of Creation Is: %f\n\n", (numerator/denominator)/2); interval = (int)((numerator/denominator)/2*RAND_MAX); if ((fp = fopen ("carnivorecreation.txt", "w")) == NULL) { printf ("\nError: Unable to open file"); return 1; } duration = end + time (0); while ( time (0) < duration ) { sample = rand (); fprintf (fp,"Carnivore Creation Log"); fprintf (fp, "Day: %d\t", total); if (sample < interval) { fprintf (fp, "Created\n\n"); created++; } else fprintf (fp, "Not Created\n\n"); total++; } printf ("Enter the Numerator for Destruction: "); scanf ("%f", &numerator); printf ("Enter the Denominator for Destruction: "); scanf ("%f", &denominator); printf ("\nProbability Of Destruction Is: %f\n\n", (numerator/denominator)/2); interval = (int)((numerator/denominator)/2 *RAND_MAX); if ((fp = fopen ("carnivoredestruction.txt", "w")) == NULL) { printf ("\nError: Unable to open file"); return 1; } duration = end + time (0); while ( time (0) < duration ) { sample = rand (); fprintf (fp,"Carnivore Destruction Log"); fprintf (fp, "Day: %d\t", total); if (sample < interval) { fprintf (fp, "Destroyed\n\n"); created++; } else fprintf (fp, "Not Destroyed\n\n"); total++; } return 0; }

Thanks in advance,

JOlszewski