title: c++ programming arrays to of find number of integers in range
body: <p>The question is attached and so I've tried to solve this but the output I'm getting is large numbers which is probably garbage data and therefore is  definitely not correct.</p>
  
  <p><a href="https://i.stack.imgur.com/6edlk.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6edlk.jpg" alt="enter image description here"></a></p>
  
  <p>Here is my code</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  using namespace std;
  const int size=8;
   void readData(char filename[], int list[], int size)
   {
  
       ifstream fin;
       fin.open("HW4_Q1data.txt");
  int value=0;
       for(int i=0;i&lt;30;i++)
       {
           fin&gt;&gt;filename[i];
           value=filename[i];
       if (value &gt;= 0 &amp;&amp; value &lt;= 24)
         list[0]++;
  
         else if (value &gt;= 25 &amp;&amp; value &lt;= 49)
         list[1]++;
  
         else if (value &gt;= 50 &amp;&amp; value &lt;= 74)
         list[2]++;
  
         else if (value &gt;= 75 &amp;&amp; value &lt;= 99)
         list[3]++;
  
         else if (value &gt;= 100 &amp;&amp; value &lt;= 124)
         list[4]++;
  
         else if (value &gt;= 125 &amp;&amp; value &lt;= 149)
         list[5]++;
  
         else if (value &gt;= 150 &amp;&amp; value &lt;= 174)
         list[6]++;
  
         else if (value &gt;= 175 &amp;&amp; value &lt;= 200)
         list[7]++;
       }
  
         fin.close();
   }
   void print(int list[], int size)
   {
       cout &lt;&lt; "   Range"&lt;&lt;'\t'&lt;&lt;"# of students"&lt;&lt;endl;
  cout &lt;&lt; "0-24:    " &lt;&lt;'\t'&lt;&lt;list[0] &lt;&lt; endl;
  cout &lt;&lt; "25-49:   " &lt;&lt; '\t'&lt;&lt;list[1] &lt;&lt; endl;
  cout &lt;&lt; "50-74:   " &lt;&lt;'\t'&lt;&lt; list[2] &lt;&lt; endl;
  cout &lt;&lt; "75-99:   "   &lt;&lt;'\t'&lt;&lt; list[3] &lt;&lt; endl;
  cout &lt;&lt; "100-124: " &lt;&lt;'\t'&lt;&lt; list[4] &lt;&lt; endl;
  cout &lt;&lt; "125-149: " &lt;&lt;'\t'&lt;&lt;list[5] &lt;&lt; endl;
  cout &lt;&lt; "150-174: " &lt;&lt;'\t'&lt;&lt; list[6] &lt;&lt; endl;
  cout &lt;&lt; "175-200: " &lt;&lt;'\t'&lt;&lt; list[7] &lt;&lt; endl;
  
   }
  int main()
  {
  
      char filename[70];
      int list[size];
  
      readData(filename,list,size);
      print(list,size);
  
      return 0;
  }
  </code></pre>