Reading from an Array of Structs

Okay I have to read information from an array of structs and compare them to an average, printing out the structs that are greater than the average. Problem is, I don't know how to read from an array to get the information from each different struct.

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>

using namespace std;

const int MAXHOUSEHOLDS = 25;

struct household
{
string IDnumber;
int annual_income;
int household_members;
bool ispoor;
};

void gethouseholds (ifstream &, household [], int &, int &);
//reads each household
int find_average (const household [], int);
void print_over_average (ostream &, const household [], int num_items, int average);
int below_poverty_level (const household [], int num_items);
//above procedure finds percentage of households below poverty level
//plus sets the ispoor flag
bool below_poverty (const household &);
//single record of type household

int main ()
{
ifstream P3datin;
ofstream P3datout;
household houselist [MAXHOUSEHOLDS];
int num_items, average, percent, numhousehold;
//significant data in array

gethouseholds (P3datin, houselist, num_items, numhousehold);
find_average (houselist, average);
P3datout<<"The average household income, rounded up to "<<
"the nearest dollar, is $"<<average<<endl;
P3datout<<"ID Number\t"<<"Annual Income\t"<<"Household Members"<<endl;
print_over_average (P3datout, houselist, num_items, average);
below_poverty_level (houselist, num_items);


cout<<"Program has finished!!!"<<endl;

system ("pause");
return 0;
}

void gethouseholds (ifstream & P3datin, household houselist [], int & num_items, int & numhousehold)
{
int p;
p=0;
num_items=0;

P3datin>>houselist[num_items].IDnumber;
while (P3datin)
{
P3datin>>houselist[num_items].annual_income;
P3datin>>houselist[num_items].household_members;
num_items++;

p=10830+3740*(household[num_items].household_members-1);
if (p<household.annual_income)
ispoor=true;
else
ispoor=false;
numhousehold++;

P3datin>>houselist[num_items].IDnumber;
}
}

int find_average (const household houselist [], int )
{
int total_income;
counter=0;
total_income=0;
average=0;



counter++;
total_income=total_income+household[num_items].annual_income;
average=(total_income * 1.0)/counter+.5;
}

void print_over_average(ostream & P3datout, const household houselist [], int num_items, int average)
{
int counter;
num_items=0;

int below_poverty_level;
}

int below_poverty_level (const household houselist [], int num_items, int average)
{


P3datout<<"The approximate percentage of homes beneath the FPL is "<<num_items<<endl;
}

bool below_poverty (const household houselist &)
{
int p;
p=0;

p=10830+3740*(household.household_members-1);

if (p<household[num_items].annual_income)
ispoor=true;
else
ispoor=false;
}

Topic archived. No new replies allowed.