Hello. After reading other threads that inut from a text file to a basic array I do not understand how to apply it to a 2d array. I dont quite understand what I need to do to make it read in the data properly. This is what I have so far...
int main()
{
const int PEOPLE = 5, PRODUCTS = 6;
double sales[ PEOPLE ][ PRODUCTS ] = { 0.0 }, value,
totalSales, productSales[ PRODUCTS ] = { 0.0 };
unsigned int salesPerson, product;
fstream infile;
infile.open("sales.txt");
if (infile.bad())
{
cerr << "Unable to open file" << endl;
exit (1);
}
for(int i = 0; i < PEOPLE ; i++)
{
for(int j = 0; j < PRODUCTS; j++ )
{
infile >> salesPerson >> product >> value;
sales[ salesPerson ][ product ] += value;
}
}
I am aware that the line infile >> salesPerson >> product >> value;
is incorrect and causes the program to crash but do not know what to replace it with.
Thanks!