title: WHILE loop and data entry
body: <p>I tried earlier to use a <code>for</code> loop to put data in but became too problematic. So I tried to use a <code>while</code> loop, it works but when I tried to debug it it continued to put <code>-858993460</code> into every slot. The <code>.dat</code> file is in the right spot and opens. </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  using namespace std;
  
  struct record
  {
      int item_id;
      string item_type;
      float item_price;
      int num_stock;
      string item_title;
      string item_author;
      int year_published;
  };
  
  void read_all_records(record records[], int &amp;valid_entries);
  int num_inventory_of_type(record records[], string type, int &amp;valid_entries);
  const int max_array = 100;
  int main()
  {
      int valid_entries = 0;
      record records[max_array];
      read_all_records(records, valid_entries);
  
      cout &lt;&lt; "Stock Report" &lt;&lt; endl;
      cout &lt;&lt; "------------" &lt;&lt; endl;
      int book = num_inventory_of_type(records, "book", valid_entries);
      cout &lt;&lt; "Book's In Stock: " &lt;&lt; book &lt;&lt; endl;
      int cd = num_inventory_of_type(records, "cd", valid_entries);
      cout &lt;&lt; "CD's In Stock: " &lt;&lt; cd &lt;&lt; endl;
      int dvd = num_inventory_of_type(records, "dvd", valid_entries);
      cout &lt;&lt; "DVD's In Stock: " &lt;&lt; dvd &lt;&lt; endl;
  
      return 0;
  }
  
  void read_all_records(record records[], int &amp;valid_entries)
  {
      ifstream invfile;
      invfile.open("inventory.dat"); 
      if (!invfile.is_open())
      {
          cout&lt;&lt;"file open failed";
          exit(1);
      }
      while(invfile.good() &amp;&amp; valid_entries &lt; max_array)
      {
          invfile &gt;&gt; records[valid_entries].item_id &gt;&gt; records[valid_entries].item_type
              &gt;&gt; records[valid_entries].item_price &gt;&gt; records[valid_entries].num_stock
              &gt;&gt; records[valid_entries].item_title &gt;&gt; records[valid_entries].item_author
              &gt;&gt; records[valid_entries].year_published;
          if(!invfile.good())
              break;
          valid_entries++;
  
      }
      invfile.close();
  
  }
  int num_inventory_of_type(record records[], string type, int &amp;valid_entries)
  {
      int count = 0;
      int holder = 0;
      for (int count = 0; count&lt;valid_entries; count++);
      {       
          if (records[count].item_type == type)
          {
              holder+=records[count].num_stock;
  
          }
      }
  
      return holder;
  }
  </code></pre>
  
  <p>the .dat file is</p>
  
  <pre class="lang-none prettyprint-override"><code>123456
  book
  69.99
  16
  Problem_Solving_With_C++
  Walter_Savitch
  2011
  123457
  cd
  9.99
  32
  Sigh_No_More
  Mumford_and_Sons
  2010
  123458
  dvd
  17.99
  15
  Red_State
  Kevin_Smith
  2011
  123459
  cd
  9.99
  16
  The_Church_Of_Rock_And_Roll
  Foxy_Shazam
  2012
  123460
  dvd
  59.99
  10
  The_Walking_Dead_Season_1
  Robert_Kirkman
  2011 
  </code></pre>
  
  <p>all are on new lines, no spaces. </p>
  
  <p>Basically it should start, run the <code>read_all_records</code> function and put the <code>.dat</code> data into the array. However, I put the <code>cout &lt;&lt; records[count].item_id;</code> in the while loop just to see if the data was actually going in, and I get <code>-858993460</code> each time. After that it should run the next function 3 times and return how many of each books there are. </p>