Find minimum of integers function always returns zero

When compiled, this program gives:
The number of grades is 75
The average is: 68.92
The highest grade is 100
The lowest grade is 0
The number of grades above the average is 38
The number of grades below the average is 37

However, the lowest grade should be 11. I can change line 87 in function CalculateHighest in such a way that instead of 'numGrades' in the for loop, it will be a random number less than 75. And the 'highest' number returned is correct. However, for 'lowest', it will always return 0. I was wondering if anyone might be able to point out where my code has gone wrong.
The txt file in question contains:
28
48
67
84
91
55
88
99
32
11
68
95
55
66
77
88
99
100
99
98
77
42
88
87
95
55
88
99
32
12
23
45
55
66
77
88
99
100
99
98
37
44
61
87
93
55
88
99
32
12
23
45
55
66
77
88
99
100
99
98
44
49
66
84
79
55
88
99
32
57
42
45
55
66
77
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;

  int numGrades;           // Number of grades
  float average;           // Average grade
  int highest;             // Highest grade
  int lowest;              // Lowest grade
  int aboveAverage;        // Number of grades above the average
  int belowAverage;        // Number of grades below the average
  int grades[101];         // Array of grades

void CalculateStatistics(ifstream& inData);
void OpenFiles(ifstream& inData, ofstream& outData);
void InputGrades(ifstream&);
void CalculateAverage(ifstream& inData);
void CalculateHighest(ifstream& inData);
void CalculateLowest(ifstream& inData);
void CalculateAboveAverage(ifstream& inData);
void CalculateBelowAverage(ifstream& inData);
void PrintResults(ofstream& outData);


int main()
{
	ifstream indata;
	ofstream outdata;
	OpenFiles(indata, outdata);
	CalculateStatistics(indata);
	PrintResults(outdata);
	
	indata.close();
	outdata.close();
	
	

return 0;
}

void CalculateStatistics(ifstream& indat)
{
	InputGrades(indat);
	CalculateAverage(indat);
	CalculateHighest(indat);
	CalculateLowest(indat);
	CalculateAboveAverage(indat);
	CalculateBelowAverage(indat);
}

void OpenFiles(ifstream& indat, ofstream& outdat)
{
	indat.open("C:/Users/Sean/Desktop/pocketcpp/A5Q1.txt");
		if(!indat)
			{
				cout << "File was not opened." << endl;
			}
			
	outdat.open("C:/Users/Sean/Desktop/pocketcpp/A5durr.txt");
	if (!outdat)
	{
		cout << "Didn't work!" << endl;
	}
}

void InputGrades(ifstream& indat)
{
numGrades = 75;
	for (int i = 0; i < numGrades; i++)
		indat >> grades[i]; 
	
	cout << "The number of grades is " << numGrades ;
}

void CalculateAverage(ifstream& indat)
{		
float sum = 0;
numGrades = 75;
	for (int i = 0; i < numGrades; i++)
		sum += grades[i];
	average = sum/numGrades;
	cout << endl << setprecision(4) << "The average is: " << average << endl;
}

void CalculateHighest(ifstream& indat)
{
	for(int i = 0; i < numGrades; i++)
		{
			if (highest < grades[i])
				highest = grades[i];
		}
	
	cout << "The highest grade is " << highest << endl;
}

void CalculateLowest(ifstream& indat)			//Where my trouble is
{
	for (int i = 0; i < numGrades; i++)
		{
			if (lowest > grades[i])
				lowest = grades[i];
		}
	
	cout << "The lowest grade is " << lowest << endl;
}

void CalculateAboveAverage(ifstream& indat)
{
	for (int i = 0; i < numGrades; i++)
		{
			if (average < grades[i])
			aboveAverage++;
		}
	cout << "The number of grades above the average is " << aboveAverage << endl;
}

void CalculateBelowAverage(ifstream& indat)
{
	for (int i = 0; i < numGrades; i++)
		{
			if (average > grades[i])
			belowAverage++;
		}
	cout << "The number of grades below the average is " << belowAverage << endl;
}

void PrintResults(ofstream& outdat)
{
	outdat << "The number of grades is " << numGrades ;
	outdat << endl << setprecision(4) << "The average is: " << average << endl;
	outdat << "The highest grade is " << highest << endl;
	outdat << "The lowest grade is " << lowest << endl;
	outdat << "The number of grades above the average is " << aboveAverage << endl;
	outdat << "The number of grades below the average is " << belowAverage << endl;
}
1
2
3
4
5
6
7
8
9
10
11
void CalculateLowest(ifstream& indat)			//Where my trouble is
{
	lowest = grades[0];  //<<-------------------------------add this
	for (int i = 0; i < numGrades; i++)
	{
		if (lowest > grades[i])
			lowest = grades[i];
	}

	cout << "The lowest grade is " << lowest << endl;
}
I've yet to post a question that isn't solvable with one line of code....many thanks, Yanson.
Topic archived. No new replies allowed.