//	-----------------------------
//	Dr. Joseph Manthey
//	----------------------------

# include
using namespace std;

int main( )
{
	//	constants

	const int LOW = 0;
	const int HIGH = 100;

	//	variables

	int grade;
	int count = 0;
	int total = 0;
	double average;

	//	enter grades

	cout << "Enter a grade (999 to stop): ";
	cin >> grade;

	while (grade != 999)
	{
		if ((grade >= LOW) && (grade <=HIGH))
		{
			count++;
			total += grade;
		}
		else
		{
			cout << "Enter grades in the range [" 
				 << LOW << "," << HIGH << "]" <> grade;	
	}

	//	print average

	if (count == 0)
	{
		cout << "Cannot compute the average without any data." << endl;
	}
	else
	{
		average = static_cast(total)/static_cast(count);
		cout << "The average grade is = " << average << endl;
	}
	
	return 0;
} 

    Source: geocities.com/vuumanj/Cpp

               ( geocities.com/vuumanj)