i am very new to c++ and have to create a program that will manage the sales of 40 different stores. I was told to use 2 (parralel) arrays(not a two dimensional array). I have no idea how to add the proper data i need becuase the file i am using to get the data only has sales for one day and has more than one data for each individual store. i somehow have to add all the sales of each indidual store into an array for the store number and that stores sales.
the file i have to get my data looks like this(notice it is random and the store numbers repeat themselves)
//store number--store sales
1 25
2 15
3 42
2 34
1 12
...
here is what i have doen so far i know i will have to use some type of searching function to find repeating store data and then add the sum but the data i am getting is not right.
int LinearSearch(int NumerToFind, int Size, int a[]);
int main ()
{
int index;
int arraysize;
int StoreID;
int ProductsSold;
int ID[40];
int Sales[40];
arraysize=40;
ifstream indata;
indata.open("boxes.dat");
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;
}
for(int c=0; c<40 ; c++)
cout<<ID[c]<<"------"<<Sales[c]<<endl;
return 0;
}
int LinearSearch(int toFind, int aSize, int a[])
{
for (int i=0; i<aSize; i++)
{
if (a[i]==toFind)
return i;
}
return -1;
}