You're off to a right start on the reading,but you need to use a different method of stopping the loop, and getting next data. Your code:
indata>>StoreID;
indata>>ProductsSold;
for(int size=0; size<40; size++)
{
StoreID=Sales[size];
index = LinearSearch(StoreID, arraysize, ID);
if (index<0)
{
ID[size]=StoreID;
Sales[size]=ProductsSold;
size++;
}
else
Sales[size] += ProductsSold;
} is set to run for 40 items from the file, no matter how few or many there are. You need to stop when the data runs out. In the loop, why do you set StoreID to the contents of Sales[size]? That makes no sense. The if/else code looks mostly ok, except you don't want to add to Sales[size], you want Sales[index]. Now, where do you get the next data items to process?
Here's an improvement:
int size = 0;
while( size < 40 && indata >> StoreID )
{
indata >> ProductsSold;
index = LinearSearch(StoreID, arraysize, ID);
if ( index < 0 )
{
ID[size] = StoreID;
Sales[size] = ProductsSold;
size++;
}
else
Sales[index] += ProductsSold;
}
for(int c = 0; c < size ; c++)
cout << ID[c]<<"------" << Sales[c] << endl;
Please put some space between operators and their operands - it helps readability.
Val