I'm trying to read numbers from a data file into array but when I compile and run nothing shows up.
what did I do wrong. I have to do all the reading from the function readData and I need to get rid of the header line but I just put that there for myself. Heres the data file
HouseNumber Price
329 155000
459 160000
505 185000
500 215000
345 210000
456 305000
344 405000
501 355000
401 190000
300 170000
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;
const int HOME_NUMBERS = 10;
const int PRICE = 2;
void programDescription();
void readData(ifstream &inFile,int homeInfo[][PRICE]);
void avgCalc(int homeInfo[][PRICE]);
void sortArray();
void writeResult();
int main()
{
//Program Description
//programDescription();
//Declare variables
string line;
int homeInfo[10][2];
ofstream outFile;
ifstream inFile;
//Open file for input
inFile.open("prices.txt");
if(inFile.fail())
{
cout << "Error opening file" << endl;
exit(1);
}
//Opens file for output
outFile.open("homeData.txt");
if(outFile.fail())
{
cout << "Error opening file" << endl;
exit(1);
}
//Process data as read and display in tabular format
//Function call
readData(inFile,homeInfo);
//avgCalc(homeInfo);
return 0;
}
void readData(ifstream &inFile, int homeInfo[][PRICE])
{
int i = 0;
while(i < HOME_NUMBERS && !inFile.eof())
{
for(int j = 0; j < PRICE; j++)
homeInfo[i][j];
i++;
}
}
void avgCalc(int homeInfo[][PRICE])
{
float avg = 0;
float sum = 0;
for(int i = 0; i < HOME_NUMBERS; i++)
sum+=homeInfo[i][1];
avg = sum/PRICE;
cout << "The average of the prices is: " << avg << endl;
}