This program needs to read the infile and calculate the temperatures for each function. I can only get it to output 0's. Can someone explain the steps needed to make this code work correctly? What am I missing? Should I be passing by reference? If so how??
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
int getData();
double averageHigh();
double averageLow();
double indexHighTemp();
double indexLowTemp();
int i, j;
double hsum = 0, lsum = 0;
double avgh, avgl;
double high = 0, low = 0;
int ind;
int const row = 2, col = 12, num = 12;
double temp[row][col];
int main()
{
cout <<"Processing Data"<<endl;
getData();
averageHigh();
averageLow();
indexHighTemp();
indexLowTemp();
cout <<" "<<endl;
system("PAUSE");
return 0;
}
int getData()
{
ifstream inFile;
inFile.open ("c:\\Ch9_Ex9Data.txt");
if (!inFile)
{
cout << "Unable to open input file!"<<endl;
return 1;
}
inFile >> high >> low;
}
double averageHigh()
{
for(int i=0;i<row;i++)
{
for(int j=0;j<col;j++)
{
hsum = (hsum + (temp[0][i]));
}
}
avgh = hsum / 12;
cout << "Average high temperature: ";
cout << avgh <<endl;
return 0;
}
double averageLow()
{
for(int i=0;i<row;i++)
{
for(int j=0;j<col;j++)
{
lsum = (lsum + (temp[1][i]));
}
}
avgl = lsum / 12;
cout << "Average low temperature: ";
cout << avgl << endl;
return 0;
}
double indexHighTemp()
{
ind = 0;
for(int i=0;i<row;i++)
{
for(int j=0;j<col;j++)
{
if (high <= (temp[0][i]))
{
high = (temp[0][i]);
ind = i;
}
}
}
cout << "Highest temperature: ";
cout << (temp[0][ind]) << endl;
return 0;
}
double indexLowTemp()
{
ind = 0;
for(int i=0;i<row;i++)
{
for(int j=0;j<col;j++)
{
if (low >= (temp[1][i]))
{
low = (temp[1][i]);
ind = i;
}
}
}
cout << "Lowest temperature: ";
cout << (temp[1][ind]) << endl;
return 0;
}