Question: c program add a report to count the total number of beaches in the file and how many are open, and how many are closed.

c programc program add a report to count the total number of beaches

add a report to count the total number of beaches in the file and how many are open, and how many are closed. . It must be determined whether the beach is to be closed or not. Right after the average has been output, you will need an if statement to decide whether the beach is to be closed or not. If the average is below 3500 print out the beach number and a short message that the beach is safe; if greater than or equal to 3500 print out the beach number and a short message that the beach is closed.

//include the required header file.

#include "stdio.h"

//Define the main function.

int main(void)

{

//Declare the variable.

int b_num, num_samples, num_orgs_per_100;

char c = 'a';

//Create a file pointer.

FILE *in_file;

//Open the file in read mode.

in_file = fopen("inp.txt", "r");

//Check if the file exists.

if (in_file == NULL)

printf("Error opening the file. ");

//Read the data from the file.

else

{

//Get the beach number and number of

//samples from the file.

fscanf(in_file, "%d", &b_num);

fscanf(in_file, "%d", &num_samples);

//Check for end of file and beach

/umber value and dispaly the samples.

while(!feof(in_file))

{

printf(" b_num = %d, num_samples = %d",

b_num,num_samples);

for(int i =0;i

{

fscanf(in_file, "%d", &num_orgs_per_100);

//Display the input number.

printf(" Sample value %d: %d",i+1,

num_orgs_per_100);

}

//Read the newline, number of samples and b_num for

/ext record

fscanf(in_file, "%c", &c);

printf(" ");

fscanf(in_file, "%d", &b_num);

fscanf(in_file, "%d", &num_samples);

}}

//Close the file.

fclose(in_file);

return 0;

}

37 5 2800 3570 2340 5600 4300 21 3 3100 4590 2340 47 4 4587 2367 3475 3400 66 4 5668 5939 5735 3653 91 2 3100 5690

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!