title: Outputting Data From A File Into Structs And Arrays Of Structs
body: <p>I am having a lot of trouble being able to get data from a file and input it into given structs and arrays of structs and then outputting the file. We are given a file that contains 96 lines and looks like this:</p>
  
  <blockquote>
    <p>Arzin, Neil<br/>
    2.3 6.0 5.0 6.7 7.8 5.6 8.9 7.6<br/>
    Babbage, Charles<br/>
    2.3 5.6 6.5 7.6 8.7 7.8 5.4 4.5<br/></p>
  </blockquote>
  
  <p>This file continues for 24 different people and then repeats with different scores (the second line).
  The first number, in this case is 2.3 for both people is a difficulty rating. The next 6 numbers are scores. </p>
  
  <p>We are given this data in order to set up our structs and arrays and my code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;iomanip&gt;
  #include &lt;string&gt;
  #include &lt;cmath&gt;
  using namespace std;
  int main ()
  {
  
    ifstream inFile;
    inFile.open("C://diveData.txt");
  
    // checking to see if file opens correctly
    if (!inFile)
    {
        cout &lt;&lt; "Error opening the file!" &lt;&lt; endl;
    }
  
    const int numRounds = 2;              // variable to hold the number of rounds
    const int numScores = 7;              // variable to hold the number of rounds
    const int numDivers = 24;             // variable to hold the number of divers
    typedef double DifficultyList[numRounds];   // 1D array for storing difficulty                of dives on each round 
    typedef double ScoreTable [numRounds] [numScores]; // 2D array of dive scores
  
  // struct to store information for one diver
    struct DiverRecord
  {
     string name;
     double totalScore;
    double diveTotal;
    DifficultyList diff;
    ScoreTable scores;
  };
  
  DiverRecord DiverList[numDivers];
  
  // my attempt at printing out the contents of the file
    while (!EOF)
   {
      for (int x = 0; x &lt; 25; x++)
      { 
         infile &gt;&gt; DiverList[x].name;
         inFile &gt;&gt; DiverList[x].totalScore;
         inFile &gt;&gt; DiverList[x].diveTotal;
  
         cout &lt;&lt; DiverList.[x].name &lt;&lt; endl;
         cout &lt;&lt; DiverList.[x].totalScore &lt;&lt; endl;
         cout &lt;&lt; DiverList.[x].diveTotal &lt;&lt; endl;
      }
    }
  
  return 0;
  }
  </code></pre>