Preview:
#include <iostream>
using namespace std;

// here we use flag method to count the average grade

int main()
{
	bool seenEndofInput;
	int numofStudents, sum;
	int curr;
	double average;

	cout << "Write grades by separated space" << endl;
	cout << "End of grades by typing -1" << endl;

	numofStudents = 0;
	sum = 0;

	seenEndofInput = false;

	while (seenEndofInput == false) {
		cin >> curr;

		if (curr == -1) {
			seenEndofInput == true;
		}
		else {
			sum += curr;
			numofStudents++;
		}
	}

	average = (double)sum / (double)numofStudents;


	cout << "The class average grade is " << average << endl;

	return 0;
}
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter