Hello Everyone,
I'm tying to make a C program which determines the level of bacteria for some beaches.
The program is supposed to access the data from a txt file and give the result.
Here's what I've been able to do so far.
I have no idea where to go from here, so please help!!
The text file is attached. The first number in the txt file refers to the lake ID, the second number to the beach number, the third number refers to the number of samplings and the rest of the numbers are the samplings of the number of organisms in 100ml of water.
Code:
#include <stdio.h>
int
main (void)
{
FILE * july01;
int lake_id, beach_num, num_samplings, num;
double num_organisms, tot_organisms;
july01 = fopen ("july01.txt", "r");
tot_organisms = 0;
while (fscanf (july01, "%d %d %d", &lake_id, &beach_num, &num_samplings) != EOF)
{
tot_organisms = 0;
for (num = 1; num <= num_samplings; num++)
{
fscanf(july01, "%d", &num_organisms);
tot_organisms = tot_organisms + num_organisms;
}
if (((tot_organisms / num_samplings) / 100) > 0.5)
printf ("Close");
else if (num_samplings < 3)
printf ("Insufficient Data");
else if (((tot_organisms / num_samplings) / 100) <= 0.5)
printf ("Open");
}
fclose (july01);
}
Here are the conditions for the program
If the average level is above 50/100ml, close the beach.
If there are less than 3 samplings, there is insufficient data.
The program should show for each beach on separate lines the name
of the lake, the name of the beach, and the recommendation ("open",
closed" or "insufficient data"). Use the table below to convert IDs
and numbers into names.
Lakes
1: Ontario
2: Erie
3: Huron
Beaches
101: Kew Beach
102: Sunnyside Beach
201: Port Dover
202: Port Burwell
301: Goderich
302: Sauble Beach