Can someone please look at the following code and help me out ?
I am trying to calculate the total family income and size for a file of individuals. The assumption is that any person who has the same last neme as the previous person in the file is part of the same family ? I am not getting any errors but when I run the file I am getting some really strange numbers for total income and family size.
//familyTaxfile.cpp - reads in names of individuals, sorts alphabetically
//by the person's last name and calculates total income fpr a household and
//any applicable tax
//
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
// Worker Type Definition
struct Worker {
string lname;
string fname;
double income;
float totalIncome;
int fSize;//size of family
};
const int WORKMAX = 10000;
void ReadWorkerFile(const string& fname, Worker w[], int& wCount);
int main()
{
Worker work[WORKMAX];
int workcount;
int i,j;
string fname;
cout<<"Enter the name of the file > ";
cin>>fname;
ReadWorkerFile(fname,work,workcount);
for (i = 0; i < workcount - 1; i++)
for (i = 0; i < workcount - 1; i++)
for(j = 0; j <workcount-1;j++)
if(work[j].lname>work[j+1].lname){
Worker tmp = work[j];
work[j] = work[j+1];
work[j+1]=tmp;
}
for (i = 0; i < workcount; i++)
cout<<work[i].lname<<" "<<
work[i].fname<<" $"<<work[i].income<<endl;
for (i = 0; i < workcount - 1; i++)
if(work[i].lname == work[i+1].lname){
work[i].totalIncome = work[i].totalIncome+work[i+1].income;
work[i].fSize++;
cout<<work[i].lname<<" "<<work[i].totalIncome<<" "<<work[i].fSize<<endl;
}
return 0;