One way to do it is to check the agent array to see if it already contains an entry for the agent just read in from the file. If it already exists then just sum the sales and value into the respective sales and values column. something like this:
int FindAgent(int agnt, int maxrow)
{
for(int i = 0; i < maxrow; i++)
if( agent[i] == agnt)
return i;
return -1;
}
void display()
{
ins.open(in_file);
int total_agent[size];
//int total_amount[size];
cout<<" TOTAL SALES BY AGENT"<<endl;
cout<<"AGENT NUMBER #SALES VALUE/SALE AMOUNT"<<endl;
int i=0;
int t=0;
cout<<fixed<<showpoint;
cout<<setprecision(2);
while(!ins.eof())
{
int agnt, sals;
float val;
ins >> agnt >> sals >> val;
int row = FindAgent(agnt,i);
if( row < 0)
{
agent[i] = agnt;
sales[i] = sals;
value[i] = val;
amount[i]=sales[i]*value[i];
i++;
}
else
{
sales[row] += sals;
value[row] += val;
amount[row]=sales[row]*value[row];
}
} Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343