basic program help (structs, arrays, input/output)

http://faculty.cs.niu.edu/~byrnes/csci240/pgms/240pgm8.htm

the link to the assignment ^^

My program1 seems to be working
but I'm not sure why my my program2 isn't running
**note: program2 isn't finished yet i'm just trying to get it to run
and print out the data to make sure i'm on the right track


Program 1:

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

using namespace std;

const int NUM_MON = 12;


int main()
{


struct utilityInfo
{
char utility[80];
double monthlyExpenses[NUM_MON];
};

utilityInfo aUtility;
char name[80];
int i;
double n;


ifstream inFile;

ofstream outFile;

inFile.open("expenses2.txt");

if (inFile.fail())
{
cout << "Unable to open expenses2.txt file\n";
return 0;
}

outFile.open("binary_utilities", ios::binary);

if (outFile.fail())
{
cout << "Unable to open binary_utilities file \n";
return 0;
}

inFile.getline(name, 80);

while (inFile)
{
strcpy(aUtility.utility, name);

for (i=0; i<NUM_MON; i++)
{
inFile.getline(name, 80);
n = atof(name);
aUtility.monthlyExpenses[i] = n ;
}

outFile.write((char *) &aUtility, sizeof(aUtility));

inFile.getline(name, 80);

}

inFile.close();

outFile.close();

}


program 2




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

using namespace std;

const int NUM_MON = 12;
const int ARRAY_ELEMENTS = 10;


struct utilityInfo
{
char utility[80];
double monthlyExpenses[NUM_MON];
} teamAr [ARRAY_ELEMENTS] ;

//********** Function Prototypes

int buildArray(utilityInfo teamAr[]);



void printUtilityStat(utilityInfo teamAr[], int numUtilities);


void calcStats(double ar[], int arSize, double &sumVal, double &avgVal, double &highVal, double &lowVal);



//******main

int main()
{

buildArray(teamAr);

printUtilityStat (teamAr, ARRAY_ELEMENTS);


}

//*****************Functions
int buildArray(utilityInfo teamAr[NUM_MON])
{

utilityInfo aUtility;
ifstream inFile;
int i=0;

inFile.open("binary_utilities");

if (inFile.fail())
{
cout << "Unable to open binary_utilities file\n";
return 0;
}



inFile.read((char *) &aUtility, sizeof(aUtility));


while (inFile)
{
aUtility= teamAr[i];
i++;



inFile.read((char *) &aUtility, sizeof(aUtility));
};

inFile.close();


}



// *************next function
void printUtilityStat (utilityInfo teamAr[NUM_MON], int numUtilities)
{
int i;

for (i=0; i<ARRAY_ELEMENTS; i++)
cout << teamAr[i] << "\n";


}




a hint on where it's going wrong would be greatly appreciated.
thank you.
I'm not sure how to print my code in the code-box type formatting I've seen in other posts
Topic archived. No new replies allowed.