c program. 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.
c program. 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.
- , add a report to count the total number of beaches in the file and how many are open, and how many are 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.\n");
//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
//number value and dispaly the samples.
while(!feof(in_file))
{
printf("\nb_num = %d, num_samples = %d",
b_num,num_samples);
for(int i =0;i< num_samples;i++)
{
fscanf(in_file, "%d", &num_orgs_per_100);
//Display the input number.
printf("\nSample value %d: %d",i+1,
num_orgs_per_100);
}
//Read the newline, number of samples and b_num for
//next record
fscanf(in_file, "%c", &c);
printf("\n");
fscanf(in_file, "%d", &b_num);
fscanf(in_file, "%d", &num_samples);
}}
//Close the file.
fclose(in_file);
return 0;
}
Step by step
Solved in 3 steps with 2 images