Having trouble with averaging

This is a discussion on Having trouble with averaging within the C++ Programming forums, part of the General Programming Boards category; I am working on a program and it is not averaging properly. I cannot figure out how to fix this. ...

1. Having trouble with averaging

I am working on a program and it is not averaging properly. I cannot figure out how to fix this.

In short, the program is set up to add in grades from 0 to 100; any grades over 100 are invalid, and a grade entry of 999 should stop the loop and average the grades.

The problem I am having is that the program is counting the invalid grades, which is making the average calculation incorrect.

Here is the program:

Code:
```#include <iostream>

using namespace std;

int main()
{
int x;

count = 0;
do
{
count++;
}

do
{
cout << "The average of these grades is:  ";
{
break;
}
}

cin >> x;
return 0;
return EXIT_SUCCESS;
}```

// TEST
//
//
//
//
//
//The average of these grades is: 40

2. Either subtract 999 before you average, or break out of the loop before you add it.

3. The problem isn't occuring with the 999 entry.

When I enter an invalid entry to test the program, it is adding the invalid entry (101 in this case) to the total number of entries. It is not adding the 101 to the total grades.

As this part of the program is within the loop, I am unsure how to correct it.

Any idea?

4. You are doing count++ regardless of whether the grade is valid or not.

5. count is incremented now matter what grade is. You only want to increase it when the grade entered is valid.

Decrypt

Edit: oops, someone else posted while I was typing.

6. I tried moving the count++ up 4 lines so that it was before the totgrade statement but it didn't solve the problem. I also tried entering count = count -1 after the invalid if statement and that really messed up the calculation.

I am new to C++ and don't know what else to try.

7. I also tried reversing the order of the if statements...that didn't work either.

Shouldn't there be a way to fix this within the loop?

8. You want to include the count++ in the IF where the grade is less than 101. You would use brackets.

http://www.cprogramming.com/tutorial/lesson2.html

9. Brackets .....

OMG I knew it would be something that simple!! You have no idea how much time I have spent on this.

Thanks so much!!