Min and Max

I'm a little confused here. Anyone give me an hint on how to find the minimum of the grade out of all of the students and find the highest grade. Just a hint, and I will try to figure it out. If not I might ask for a possible solution :(

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
//Outputing data names that will be outputted on the screen. For instance, name, grades, letter grade
		cout<< " Student Statistics: " << endl <<endl<<endl;
		cout<< "Name\t" << "\tTest" << "\t    Assignments" << "\t      Points" <<"\t  Numeric " <<"\tLetter ";
		cout<< endl << "\t\t Avg" << "\t        Avg"<< "\t\t\t    Grd" << "\t\t Grd ";
	

		//Enter in first name and last name in the filetxt
		fin>>firstname >>lastname;
		fin>>testgrade1 >>testgrade2;
		fin>> assign1 >>assign2>>assign3;



	//Going into the while loop.
		while (fin)
		{
			
			
			//Print out the first and last name of the student
			cout<<left;
			cout<< "\n\n" << setw(6)<< firstname <<setw(5) <<lastname;

			//Calculate the testaverage. Round it to two decimal places, with trailing zeroes
			testaverage=(testgrade1+testgrade2)/2;
			cout<<setprecision(2) <<fixed<<showpoint;
			cout<<right<<setw(10) <<testaverage;

			//Calculate the assignment average of each student
			assignaverage=(assign1+assign2+assign3)/3;
			cout<< setw(15);
			cout<<assignaverage;

			//Calculate the total points accumalated
			totalpoints= testgrade1+testgrade2+assign1+assign2+assign3;
			cout<< setw(16) <<totalpoints;

			//Calculate the the numericgrade. Add up assignments and test, then divide by 5 to find the numericavg grade
			numericgrade= (testgrade1+testgrade2+assign1+assign2+assign3)/5;
			cout<< setw(12) <<numericgrade;


			//Let the minimum equal numericgrade
			minimum=numericgrade;
			

			//you will use the if and else statement to calculate the letter grade

			
			//If number is higher then 90. Student gets an A
			if(numericgrade>=90)
				cout<<setprecision(15)<<"\t  A";
			
			//If number is higher then 80. Students gets a B
			else if (numericgrade>=80)
				cout<<setprecision(15)<<"\t  B";

			//If number is higher then 70. Student gets a C
			else if (numericgrade>=70)
				cout<<setprecision(15)<<"\t  C";

			//Any lower then 70, gets an F
			else 
			{
				cout<<setprecision(15)<<"\t  F";
			}

			counter++;

			//Prevent the loop from becoming an infinite loop. Enter in names, scores, etc...
			fin>>firstname >>lastname;
			fin>> testgrade1 >>testgrade2;
			fin>> assign1 >>assign2>>assign3;
			
			//Add counter++ to determine the total number of students
			
		}

		//Overall Class Statistics output

		//Display Class Statistic on console
		cout<<"\n\n\n\tClass Statistics ";

		//Display number of students in class and the calculation of total students
		cout<<"\n\n\t\tNumber: "<< counter;
	_getch();
	return 0;
}

closed account (o3hC5Di1)
Hi there,

You will need two variables, minimum, initialized to the highest grade possibility and maximum, initialized to 0.
During your loop, check the grade of the current student to minimum.
If it is smaller than minimum, set minimum to this student's grade.
Similarly, If it is larger than maximum, set maximum to this student's grade.

At the end of the loop minimum and maximum will contain the lowest and highest grade respectively.

Hope that helps, please do let us know if you require any further help.

All the best,
NwN
1
2
minimum=numericgrade;
			if (minimum<numericgrade)


I did something like this; however, I'm sure this is no way close to it.
1
2
3
4
5
                                              minimum=numericgrade;
			maximum=numericgrade;

			if(minimum<numericgrade)
				minimum=numericgrade


I think this should be right :/
Last edited on
1
2
3
4

			if(minimum>numericgrade)
				minimum=numericgrade;


minimum=100

I'm official with this one and assuming its correct
closed account (o3hC5Di1)
Hi there,

This would make more sense to me reading your code, but it does the same thing:

1
2
if (numericgrade < minimum)
    minimum=numericgrade


Again, it does the same thing, but to me personally, the intent is slightly clearer.
Well done on solving it though :)

All the best,
NwN
Topic archived. No new replies allowed.