ok thanks for the help so far. I cleaned up the code and managed to get no errors after debugging, but still am not getting any output. Not sure how to add reference variables to arrays while in a function. Any help on how to do this or what my problem might be would be greatly appreciated.
Code:
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cmath>
#define size 50
using namespace std;
void headings(ofstream &outFile);
void readData(ifstream &inFile, int customer[], float balance[]);
void sort(ifstream &inFile, float balance[]);
void printResults(ofstream &outFile, ifstream &inFile, int customer[], float balance[]);
int main()
{
//declare variables
int customer[size];
float balance[size];
//open files
ifstream inFile;
ofstream outFile;
inFile.open("prog7.txt");
outFile.open("prog7.out");
// funtion to print headings
headings(outFile);
// read from file
float temp = 0;
readData(inFile, customer, balance);
// loop
while (!inFile.eof())
{
readData(inFile, customer, balance);
temp ++;
}
// function to sort in descending order
sort(inFile, balance);
// function to print results
printResults(outFile, inFile, customer, balance);
outFile.close();
inFile.close();
return 0;
}
void headings(ofstream &outFile)
{
outFile <<setw(10)<< "Customer ID"
<<setw(10)<< "Balance"
<<endl;
}
void readData(ifstream &inFile, int customer[], float balance[])
{
static int i = 0;
static int j = 0;
inFile >> customer[j] >> balance[i];
}
void sort(ifstream &inFile, float balance[])
{
float temp = 0;
for(int j=1; j< size; j++)
{
for(int i=0; i< size-1; i++)
{
if(balance[i] > balance[i+1])
{
temp=balance[i];
balance[i]=balance[i+1];
balance[i+1]=temp;
}
}
}
}
void printResults(ofstream &outFile, ifstream &inFile, int customer[], float balance[])
{
outFile << setprecision(2) << fixed << showpoint;
outFile <<setw(10)<< customer
<<setw(10)<< balance
<<endl << endl;
}