Creating a Min and Max, question

Hi, my program is supposed to get a number of students with entered gpa's and then after that find the sum, min and max. I was able to find out how to do the sum, but I am currently stuck on how to get the min and max. I was wondering if anyone can help.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  int main()
{
	int studentCount{ 1 }, maxStudentCount{ 0 };
	float sumGPA{ 0 }, inputGPA{ 0 };
	do {
		cout << "Enter the number of GPAs to process: ";
		cin >> maxStudentCount;
	} while (maxStudentCount < 0);
	if (maxStudentCount == 0)
	{
		cout << "No grades entered!";
	}
	while (studentCount <= maxStudentCount) {
		cout << "Enter GPA 0.0 to 4.0 for student #" << studentCount << ": ";
		cin >> inputGPA;
	if (inputGPA < 0.0 || inputGPA > 4.0) {
		cout << "Bad GPA entered.\n";
	}
	if (inputGPA >= 0.0 && inputGPA <= 4.0) {
		sumGPA = sumGPA + inputGPA;
		cout << " Sum of GPA is: " << sumGPA << endl;
	}
		studentCount = studentCount + 1;
	} 
the algorithm is
min = max = first value
for(all values except first)
{
if value > max them max = value
if value < min, then min = value
}

because you do not store the values, you have to work this into your get loop.
Last edited on
So would I have to create new ints?
Create, yes,
ints ... your inputs are float. Your sum of inputs is float.
Should the min and max be float or int?
Float, I just figured everything out, thank you everyone
Topic archived. No new replies allowed.