Well, it seems to me that you have two options: Use lgrade, or loop looking for the value of -1. I prefer the former.
According to your input loop, you'll stop at lgrade == 10 or input value == -1. If you input -1, you know that lgrade is one too many inputs. Same thing if you typed -1. -1 should not be considered for the average.
The following I don't understand:
1 2 3 4
|
if ( labs[lgrade-1] == 0)
{
lgrade--;
}
|
I interpret this as follows: "If the last grade entered is zero, then remove one from the lgrade counter (which before the reduction equals the total number of grades entered)". Are you saying that a grade of zero can be ignored from the average? Some kind of curve for the students? If it is, then note that for it to work you will have to make sure that you enter the zero grade for the student as the last entry or the student will not get the adjusted average. Or maybe the adjusted curve rule is "if the student got a zero in the last test, then eliminate it". If this is the rule, then I guess it is OK.
If the above code has a different purpose, then remove it because it is not acheiving such purpose.
Now the average loop:
1 2 3 4 5 6
|
avg1 = 0;
for(lx = 0; lx < lgrade; lx++)
{
avg1 += labs[lx];
}
avg1 /= lgrade;
|
At this point, avg1 should contain the correct average. Note however, that you must not touch the value of lgrade between the end of the input loop and the end of the average calculation, as lgrade represents the total number of elements in the labs array.
The same technique can be applied to the other average you calculate.
This sounds like homework to me, and I might have revealed a little too much, but it seems to me that you needed the extra push. I sure hope that this helps you truly learn this powerful programming language.