The program is supposed to take the value of the pressure for each hour every day of the year. It then determines the maximum and minimum for each day and prints it out. It also is supposed to print out the min and max of the entire year as well as the greatest and least difference between the min and max of all the days. I am having trouble properly reading the file. I keep getting some weird numbers from only the minimum, the maximum seems to be working. If somebody could possible check my code out and push me in the right direction. Any help would be appreciated.
#include<iostream>
#include<fstream>
#include<cstdlib>
#include<math.h>
usingnamespace std;
double Difference(ifstream& inData,double& yearlymin,double& yearlymax);
int main()
{
//Declaring variables
int i;
double difference;
double yearlymin;
double yearlymax;
double maxdiff;
double mindiff;
//open file for input
ifstream inData;
inData.open("barometric.dat");
//create a file for output
ofstream outData;
outData.open("differences.dat");
//Determines the difference between the min and max of each day
for (int i = 0;i < 365&&inData; i++)
{
//Get the difference from the other function
difference = Difference(inData, yearlymin, yearlymax);
//Puts that value into the differences.dat file
outData << difference <<" ";
maxdiff=(difference>maxdiff)?difference:maxdiff;
mindiff=(difference<mindiff)?difference:mindiff;
}
//prints out the yearly maximum and minimum;
cout << "The Yearly Max is: " << yearlymax << endl;
cout << "The Yearly Min is: " << yearlymin << endl;
cout << "The greatest difference for the year was: " << maxdiff << endl;
cout << "The least difference for the year was: " << mindiff << endl;
//Closes the files
inData.close();
outData.close();
system("PAUSE");
return 0;
}
//This function determines the maximum and minimum for each hour and prints out the daily max and min
double Difference(ifstream& inData,double& yearlymin,double& yearlymax)
{
//Declaring variables
double pressure;
double minimum;
double maximum;
//sets the data from the barometric file to equal the variable pressure
inData >> pressure;
//Calculates the min and max for every hour of the day
for(int i=0;i < 24&&inData;i++)
{
maximum=(pressure>maximum)?pressure:maximum;
minimum=(pressure<minimum)?pressure:minimum;
yearlymax=(pressure>yearlymax)?pressure:yearlymax;
yearlymin=(pressure<yearlymin)?pressure:yearlymin;
inData >> pressure;
}
//Prints the daily max and min
cout << "The Daily Maximum is: " << maximum <<endl;
cout << "The Daily Minimum is: " << minimum <<endl;
//returns the difference between the daily max and the min
return maximum - minimum;
}