passed or failed

Hi,

The user input name, id, and a grade for a final.
I would like to know how to find the total of student who passed the class and total who failed it.

I started with that but not sure what to do after
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
int findminmax(Student tabStudent[], int size)
{
	int max = 0;
	int min = 0;
	min = tabStudent[0].Final;
	max = tabStudent[0].Final;

	for (int i = 1; i < size; i++)
	{
		if (tabStudent[i].Final>= 60)
			max = tabStudent[i].Final;
		if (tabStudent[i].Final< 60)
			min = tabStudent[i].Final;

	}
}
Last edited on
closed account (48T7M4Gy)
One way, especially if students (clas/struct etc) are stored in a file

int no_of_students=0
for each student
   int no_of_students ++
next student


or if they are in a simple array
int no_of_students = sizeof(studentArray)/sizeof(student)


or if STL container, use the relevant size() function
But how is it comparing the grades?
closed account (48T7M4Gy)
But how is it comparing the grades?


Oops! I missed that bit but it is easily fixed:
int no_of_students_gradeA=0
int no_of_students_gradeB=0

for each student
  if student.grade == A
      no_of_students_gradeA ++

  if student.grade == B
      no_of_students_gradeB ++

etc

next student


You can use a switch, if cascade and other methods to separate and control grade count



Last edited on
Still not working :( Here is what i did:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
int findminmax(Student tabStudent[], int size)
{
	int passed = 0;
	int failed = 0;
	
	for (int i = 0; i < size; i++)
	{
		
		if (tabStudent[i].grade >= 60)
		{
			passed++;
		}
		
		else
		{
			failed++;
		}
		cout << "\n\tTotal passed :  "; cout << passed;
		cout << "\n\tTotal failed: "; cout << failed;

		return passed;
		return failed;
Last edited on
closed account (48T7M4Gy)
1. You can't have two returns unfortunately.
2. Also, your for loop is missing a brace to close it off.
3. To just have one return value, which is all you can have, then take advantage of the fact that the number failed is the no. of students minus the no. who passed. And the no. of students in total is no. passed plus no failed, if you get what I mean.

Last edited on
Topic archived. No new replies allowed.