title: How to detect data beyond certain value out of a fixed range
body: <p>I've written a c program which can read a text file with single column of data. All the data can be read into the program with the following codes:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;cstdlib&gt;
  
  main()
  {
      char temp[20];
      float t;
      int a = 0, x = 0; //a is no. of data greater than 180 and x is no of data
  
      FILE *fpt;
  
      fpt = fopen("case i.txt", "r");
  
      fscanf(fpt, "%s", temp);    // read and display the column header
      printf("%s\n", temp);
  
      while (fscanf(fpt, "%f", &amp;t) == 1)
      {
          printf("%.2f\n", t);
          ++x;                 //count for number of data
  
          if (t &gt; 180) {
            ++a;               //count for number of data &gt; 180
          }
  
          if (x &gt; 2 &amp;&amp; a == 2) {    //place where bug is expected to occur
            printf("2 out of 3 in a row is greater than 180");
            a=0;    //reset a back to zero
            x=0;
          }     
      }
  
      fclose(fpt);
      system("pause");
  }
  </code></pre>
  
  <p>The problem comes when I want to detect like <strong>2 out of 3</strong> data are <strong>beyond 180</strong> degree Celsius. I tried some ideas like when (<strong>no. of data > 2</strong>) and (<strong>two data > 180</strong>) then generate an error message, but it will have bug as it may have <strong>two data > 180</strong> but when <strong>4 data are read</strong>, that means it become <strong>2 out of 4</strong>, not <strong>2 out of 3</strong>, is it possible to be programmed? Thank you in advance for every help.</p>
  
  <p>The following is the sample data and output:</p>
  
  <p><img src="https://i.stack.imgur.com/dSva5.png" alt="enter image description here"></p>
  
  <p><img src="https://i.stack.imgur.com/aD5yN.png" alt="enter image description here"></p>