Barometric Pressure Problem

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91

#include<iostream>
#include<fstream>
#include<cstdlib>
#include<math.h>


using namespace 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;

}
Last edited on
If you think the problem is reading the file, put in a cout to confirm you can read all the values properly.
Topic archived. No new replies allowed.