Array search

I'm writing a program to average 10 grades and if the user enters "-1" in for any of the grades the program is supposed to know that the assignment hasn't been completed yet. So, if the assignment isn't completed then it won't be added into the average for all the scores.

This assignment uses arrays and I just needed some help with how to write a function that searches my grade array for the values that equal "-1" and adjusts my average to compensate for the assignments that haven't been completed.
When you're computing the average just have an if statement inside your for loop (assuming you have a for loop that sums all the grades) that will not add the grade to the total if it's value is -1. Then subtract one from your total number of grades. Should look like this:
1
2
3
4
5
6
7
8
9
for(int i = 0; i < 10; i++)
{
	if(grades[i] == -1)
	{
		numGrades--;
		continue;
	}
	total += grades[i];
}
Thanks for the help on that. It took me way too long to try and puzzle that out on my own.
Topic archived. No new replies allowed.