01: #include <string>
02: #include <iostream>
03: #include <fstream>
04: 
05: using namespace std;
06: 
07: /**
08:    Reads numbers from a file and finds the maximum value
09:    @param in the input stream to read from
10:    @return the maximum value or 0 if the file has no numbers
11: */            
12: double read_data(ifstream& in)
13: {  
14:    double highest;
15:    double next;
16:    if (in >> next)
17:       highest = next;
18:    else
19:       return 0;
20: 
21:    while (in >> next)
22:    {  
23:       if (next > highest)
24:          highest = next;
25:    }
26: 
27:    return highest;
28: }
29: 
30: int main()
31: {  
32:    string filename;
33:    cout << "Please enter the data file name: ";
34:    cin >> filename;
35: 
36:    ifstream infile;
37:    infile.open(filename.c_str());
38: 
39:    if (infile.fail()) 
40:    {
41:       cout << "Error opening " << filename << "\n";
42:       return 1;
43:    }
44: 
45:    double max = read_data(infile);
46:    cout << "The maximum value is " << max << "\n";
47: 
48:    infile.close();
49:    return 0;
50: }