Problem with inputing data into arrays and displaying

Hello, I'm new to learning C++ and was doing well until we hit Arrays. My homework is to retrieve data from a file and then add and display part of the data from the file.

A three line sample of the data in the text file looks like this:

Debra 10156 VA 15064.00
Greg 10188 DE 3264.00
Greg 10189 DE 4476.00

The first part is the Employees name, second part is the customer number, the third is the state and the last is the sales amount. The only data I actually care about are the names and sales amounts.

What I need to do is read the file(size unknown) and add each Employees sales figures together and then display their names and total sales, like this:

Debra $15064.00
Greg $7740.00

This is my code so far. I was simply trying to input the data and then display it out so far and can't even get that to work, let alone move onto adding the figures together. We just started working on arrays and two dimensional arrays, so I'm really new and any code provided would need to be pretty simple. I don't really understand how to read through a line with multiple data types and enter each one into a separate array, if I even need to do that. Thank you.

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
#include <iostream>
#include <fstream>
#define MAX 15
using namespace std;

int main()
{
ifstream myfile("customers.txt");
if (myfile.fail())
{
	cerr <<"Error 99: Cannot open file";  //displays error if file cannot be opened
	return 99;
}

char name[MAX+1], state[3];
int cust[6];
float amount[MAX+1];
int k=0;

while(! myfile.eof())
{
	myfile.getline(name, sizeof(name));
	myfile >> cust[6];
	myfile.getline(state, 3);
	myfile >> amount[MAX+1];
	++k;
}
for(int i=0; i<k; ++i)
{
	cout << name[i] << "/t$" << amount[i] << endl;
}

myfile.close();
return 0;
}


Any help would be appreciated, I know it said not to post homework but I hit a wall and couldn't find something that helped from searching.
Topic archived. No new replies allowed.