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 end;
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);
interval = (int)((numerator/denominator)*RAND_MAX);
if ((fp = fopen ("plantcreation.txt", "w")) == NULL)
{
printf ("\nError: Unable to open file");
return 1;
}
end = end + time (0);
while (time (0) < end)
{
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);
interval = (int)((numerator/denominator)*RAND_MAX);
if ((fp = fopen ("plantdestruction.txt", "w")) == NULL)
{
printf ("\nError: Unable to open file");
return 1;
}
end = end + time (0);
while (time (0) < end)
{
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);
interval = (int)((numerator/denominator)*RAND_MAX);
if ((fp = fopen ("herbivorecreation.txt", "w")) == NULL)
{
printf ("\nError: Unable to open file");
return 1;
}
end = end + time (0);
while (time (0) < end)
{
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);
interval = (int)((numerator/denominator)*RAND_MAX);
if ((fp = fopen ("herbivoredestruction.txt", "w")) == NULL)
{
printf ("\nError: Unable to open file");
return 1;
}
end = end + time (0);
while (time (0) < end)
{
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);
interval = (int)((numerator/denominator)*RAND_MAX);
if ((fp = fopen ("carnivorecreation.txt", "w")) == NULL)
{
printf ("\nError: Unable to open file");
return 1;
}
end = end + time (0);
while (time (0) < end);
{
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);
interval = (int)((numerator/denominator)*RAND_MAX);
if ((fp = fopen ("carnivoredestruction.txt", "w")) == NULL)
{
printf ("\nError: Unable to open file");
return 1;
}
end = end + time (0);
while (time (0) < end);
{
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,