Good programming practice/approach?

Recently had a quiz with this problem: "Write a program that continuously requests a grade to be entered.If the grade is less than 0 or greater than 100, your program should print an appropriate message informing the user that an invalid grade has been entered; else, the grade should be added to a total. When a grade of 999 is entered, the program should exit the repetition loop and compute and display the average of the valid grades entered."

I couldn't answer it on the quiz, but I managed to solve it on my free time. It works, but my concern is that my approach doesn't seem very "right". I've been taught that using the continue statement should be avoided. Any input on how else I could have done it?

I don't get question well enough.From what I got I think when total grade =999 program should exit from loop.If so then,
Why you used long technique to discard grade=999?
If I enter 999,then I go to else part where grade is added then subtracted.count subtracted but later added.So result is nil.but loop ends.

There is nothing wrong with what you did. I do have some suggestions though. You don't need count. Your while statement can simply check while (grade != 999) but then you have an issue, grade will still be added to total. You have a few options here. The one I suggest is to use the following code:

However, the loop posted by Volatile Pulse would cause the following issues:
1) the program would enter an infinite loop (grade stays at 84),
2) for each loop through, 84 would be added to total, and the count would increase, despite no / invalid input.

In my loop, the program is protected from an infinite loop, and data integrity is protected.

Yeh! I would definitely test if the input is not a digit. I have completed this project so I won't put up the completed code Yet.

12345678910111213141516

sudocode:
do
enter grade;
if grade is a digit ->
if grade is within given range (101 to 998)->
calculate average;
increment the number of grades entered;
elseif grade is out of range (0 to 100) or is a character ->
output error message;
while not exit code (999);
if number of grades is > 0 ->
output grade average;
else
output No grades were entered;

The cin object converts to a boolean depending on the success of a read operation. If valid, the loop continues; in the case of bad input, the loop terminates, giving the rest of the code no chance to alter the other variables.