This was a fun project.
There is an issue with your math.
And you'll need one function from the <numeric> header.
Also, your I/O could use a little help, since you are requiring it to terminate to get grades. I'll give that to you for free:
using namespace std;
cout << "What were your latest scores?\n";
vector <double> grades;
cout << "Exam " << (grades.size() + 1) << "> ";
getline( cin, s );
if (s.empty()) break;
istringstream ss( s );
ss >> temp;
cout << "Er, try again or press ENTER to stop entering grades.\n";
grades.push_back( temp );
For the remainder, some math:
The current grade is the average of all the scores, which is (sum of scores)/(number of scores).
Get the sum of scores using
double sum = accumulate( grades.begin(), grades.end(), 0 );
So the average is:
double current_grade = sum / grades.size();
Once you know that, tell the user what his current grade is before asking more questions.
Now you need to know two things:
- how many exams remain?
- what grade does the user want?
Now for the math:
desired = (sum + x) / (grades.size() + exams_remaining)
Solve for x.
Then the minimum grade required for each remaining exam is (x / exams_remaining).
Hope this helps.