Reading from file into multidimensional array

I need some advice on how to get past a huddle in my Homework. I am to write C++ program to read the file and display the results with appropriate formatting. Read from the file a person’s name, SSN, and wage, the number of hours worked in a week, and his or her status and store it in appropriate multidimensional arrays.So far I can read from the file into a string array containing the person's first name, last name and SSN. However I can't seem to figure out to integrate a second multidimensional array to capture the wage, hours worked.

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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
   1.
      #include <iostream>
   2.
      #include <fstream>
   3.
      #include <string>
   4.
      using namespace std;
   5.
       
   6.
      int main()
   7.
      {
   8.
              string file[5][10];
   9.
              double payInformation[5][10];
  10.
              char eStatus;
  11.
              double overTimePay, regularPay, netPay;
  12.
       
  13.
       
  14.
              ifstream fin("data.txt");
  15.
       
  16.
              if (fin.fail())//Check if the file is open
  17.
              {
  18.
                      cout << "File not opened..." << endl;
  19.
                      return 1;
  20.
              }
  21.
              while (!fin.eof())
  22.
              {
  23.
                      if (!fin.eof())
  24.
                      {
  25.
                              for ( int i = 0; i < 5; i++ ) // loop through the 1st dimension of the array
  26.
                                      for ( int j = 0; j < 3; j++ ) // loop through the 2nd dimension of the array
  27.
                                              fin >> file[i][j]; // read to each element of the array  
  28.
                      }
  29.
              }
  30.
       
  31.
       
  32.
       
  33.
       
  34.
              fin.close();
  35.
       
  36.
       
  37.
              system ("PAUSE");
  38.
              return 0;
  39.
      }
Last edited on
Topic archived. No new replies allowed.