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++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter5: Control Structures Ii (repetition)
Section: Chapter Questions
Problem 28PE
icon
Related questions
Question

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.

  1. , 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;

}

Expert Solution
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Datatypes
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr