Not sure where to initialize

Hey guys! I can't figure out where or what to initialize min and max to in order for this program to work with any text document. Help would be much appreciated. Thank you so much for your time.

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
 #include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;

int main()
{
	char choice;
	int reader , max, min, numberValues = 0, average = 0;
	double sumValues = 0;
	
	ifstream inputFile("random.txt");
	if (inputFile)
	{
		do
		{
			cout << "Make a slection from the list\n"
				 << "A. Get the largest value\n"
				 << "B. Get the smallest value\n"
				 << "C. Get the sum of the values\n"
				 << "D. Get the average\n"
				 << "E. Get the number of values entered\n"
				 << "F. End this program\n\n"
				 << "Enter your choice -->  ";
			cin  >> choice;

			
			while (inputFile >> reader)
			{
				if (max < reader)
					max = reader;
				if (min > reader)
					min = reader;
				numberValues++;
				sumValues += reader;
				
			}

			
			if (numberValues > 0)
			{
				average = sumValues / numberValues;
			}	

			switch (choice)
			{
				case 'A':
				case 'a': cout << "\nThe largest value is " << max << endl << endl;
				break;
				case 'B':
				case 'b': cout << "\nThe smallest value is " << min << endl << endl;
				break;
				case 'C':
				case 'c': cout << "\nThe sum of the values entered is " << sumValues << endl << endl;
				break;
				case 'D':
				case 'd': cout << "\nThe average of the value entered is " << average << endl << endl;
				break;
				case 'E':
				case 'e': cout << "\nThe number of values entered is " << numberValues << endl << endl;
				case 'F':
				case 'f':
					{
						cout << "\nProgram ending\n\n" << "Press Enter to end -->  ";
						cin.ignore();
						cin.ignore();
						return 0;
					}
				default: cout << endl << choice << " was not a valid option" << endl << endl;
				break;
			}
		} while (choice != 'F' &&  choice != 'f');
	}
	else
	{
		cout << "The program could not open the file\n";
	}
	return 0;
}
Obviously, before you calculate them. Do you see where are you calculating them?

As about values, look here are several useful constants in one of header files:
http://www.cplusplus.com/reference/climits/
At the start:
1
2
    int min; // Set to BIGGEST possible value.    
    int max; // Set to SMALLEST possible value.  


There seems to be a logic error here. These lines need to be moved outside the do-while loop.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
        while (inputFile >> reader)
        {
            if (max < reader)
                max = reader;
            if (min > reader)
                min = reader;
            numberValues++;
            sumValues += reader;    
        }
        
        if (numberValues > 0)
        {
            average = sumValues / numberValues;
        } 
Topic archived. No new replies allowed.