Help Outputting Data From File Into Structs and Arrays of Structs!

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:
Arzin, Neil
2.3 6.0 5.0 6.7 7.8 5.6 8.9 7.6
Babbage, Charles
2.3 5.6 6.5 7.6 8.7 7.8 5.4 4.5

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.

We are given this data in order to set up our structs and arrays and my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <cmath>
using namespace std;
int main ()
{

  ifstream inFile;
  inFile.open("C://diveData.txt);
  
  // checking to see if file opens correctly
  if (!inFile)
  {
      cout << "Error opening the file!" << 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 < 25; x++)
    { 
       infile >> DiverList[x].name;
       inFile >> DiverList[x].totalScore;
       inFile >> DiverList[x].diveTotal;
     
       cout << DiverList.[x].name << endl;
       cout << DiverList.[x].totalScore << endl;
       cout << DiverList.[x].diveTotal << endl;
    }
  }

return 0;
}


 


If anyone could provide some insight on this it would be really appreciated! I have been searching online and looking in my book frantically but I can not find anything that is helpful.

Thank you!
Last edited on
Missing the closing " on line 11
Topic archived. No new replies allowed.