Need help with reading from file into array

Mar 10, 2013 at 6:06pm
Hi,

I'm doing a project for school, and am at an impasse. The program is working correctly until it comes to reading data from a file via a loop into an array. It returns nothing back. Below are the results of my program:


Billable Items


Team Member Name        Team Member Amount Billed
                        0
                        0
                        0
                                Grand Total: 4100

And this is the code I'm using to read into the array:

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
void displayGrandTotal() 
{
   string clientNameHolder = " "; // We declare variables to hold our read values.
   int invoiceNumberHolder = 0;
   double grandTotalHolder = 0.00;
   string teamMemberHolder[ARRAYSIZE] = {" "};
   double memberTotalHolder[ARRAYSIZE] = {0.00};
	
   readFile.open("DataFile.txt"); // Now we open the file we read from.
   
   getline(readFile, clientNameHolder);
   readFile >> invoiceNumberHolder;
   readFile >> grandTotalHolder;
	
   // Here, we create a loop that reads all of the values in the file. 
   for (int counter = 0; counter < NumOfTM ; counter++)
   {
      getline(readFile, teamMemberHolder[counter]);
      readFile >> memberTotalHolder[counter];
   }
   
   readFile.close();
   
   // Here, we will display an Invoice number and client information.
   cout << "\n\n---------------\n\n";
   cout << "Invoice #: " << invoiceNumberHolder << endl;
   cout << "Client: " << clientNameHolder << endl;
   cout << "---------------\n\n"; /* This will give separation to the name and 
   billing items for increased readability. */

   cout << "Billable Items\n\n";

   // Here, we will start the list of billable hours.
   cout << endl << "Team Member Name\t" << "Team Member Amount Billed\n";
		
   for (int index3 = 0; index3 < NumOfTM; index3++) /* This will display the billing 
   information on the bill. */
   {
      cout << teamMemberHolder[index3] << "\t\t\t" << memberTotalHolder[index3];
      cout << endl;
   }


Any Ideas?
Mar 10, 2013 at 6:12pm
What does the contents of the input file look like, please. A sample of the data would be helpful.
Mar 10, 2013 at 9:08pm
Oops, that would be helpful, right?
Funco
42
2600
Jimmy Starnes
350
Eve Starnes
750
Brad Watson
1500
Topic archived. No new replies allowed.