Help with while Loop

Hi Everyone, so for my project I needed to make a loop and get a certain amount of grades from the user and average them. I have gotten that part down but the last part is to show how many of the entered grades, in my case six, have passed or failed and I can't get my head around how to do it. The only solution I know of how to usually show grades is through if/else but my professor wants us to get the number of students who failed or pass. EX. 4 students passed, 2 students failed. Any tips or corrections to resolve this would be greatly appreciated.

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

int main()
{
	int total, 			//sum of grades
		gradeCounter,		//number of grades entered
		grade,			//one grade
		average;		//average of entered grades


	//initialize the loop
	total = 0;			//clear total
	gradeCounter = 1;		//prepare to loop

	//Start a while loop to acquire the students six grades
	while (gradeCounter <= 6)
	{
		cout << "Enter your six grades. " << endl; //prompt for input
		cin >> grade;
		total = total + grade; // add grade total
		gradeCounter = gradeCounter + 1; //increment counter
	}

	//Output the average of the grades
	average = total / 6;
	cout << "The average is " << average << endl;
	//Output the number of students who failed and passed
	if (grade > 70){
		cout << ""
	}


	system("pause");
	return 0;
}
It is easier then you think:
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
#include <iostream>
using namespace std;

int main()
{
	int total, 			//sum of grades
		gradeCounter,		//number of grades entered
		grade,			//one grade
		average;		//average of entered grades

int students_passed = 0; // Note: Initialize here
int students_failed = 0; // Note: Initialize here


	//initialize the loop
	total = 0;			//clear total
	gradeCounter = 1;		//prepare to loop

	//Start a while loop to acquire the students six grades
	while (gradeCounter <= 6)
	{
		cout << "Enter your six grades. " << endl; //prompt for input
		cin >> grade;
		total = total + grade; // add grade total
		gradeCounter = gradeCounter + 1; //increment counter

if (grade > 70) // Note
  students_passed = students_passed + 1; // ++students_passed;
else
  students_failed = students_failed + 1;
	}

	//Output the average of the grades
	average = total / 6;
	cout << "The average is " << average << endl;
	//Output the number of students who failed and passed
cout << "students passed: " << students_passed << endl; // Note
cout << "students failed: " << students_failed << endl; // Note


	system("pause");
	return 0;
}
Topic archived. No new replies allowed.