Determine grade from tests scores entered

I'm pretty new to c++, and I've been trying to fix a few quirks with my program that is able to determine someone's grade by using while loops. The program needs to loop after the scores have been added up and displayed. However, in the do-while loop, the condition seems to not apply and goes straight through when i don't enter any input in the name field. After scores are added and displayed, it goes back to the enter name prompt again but no matter i put in, it never loops. I also want all input to be cleared after the grade has been displayed but i don't think i used cin.clear() correctly at the end of the do-while loop. What needs to be done?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
 #include <iostream>
#include <string>
#include <iomanip>
using namespace std;

int main()
{
	string name;
	int score, tests = 0, total = 0;	// Tests will be used to determine the amount of scores entered
	double avg = 0;
	bool errorflag = false;

	cout << "Greater Grader \n" << endl << " This program will process test scores to provide to individuals \n with letter grades according to the following scale :" << endl;
	cout << endl <<
		"			*******************************************	\n"			// Display of grading scale
		"			90	<	average			A	\n"
		"			80	<	average	<=	90	B	\n"
		"			67.5	<	average	<=	80	C	\n"
		"			55	<	average <=	67.5	D	\n"
		"			 0	<	average	<=	55	F	\n"
		"			*******************************************" << endl;
		
	cout << fixed << showpoint << setprecision(1);
	
	cout << "Type your name (press ENTER to terminate) : " << endl;
	getline(cin, name);

	do
	{
		if (cin.fail())
		{
			errorflag = true;
			cin.clear();
		}

		cout << endl << "\n Enter your scores and end the list with a negative number : ";
		cin >> score;
		while (score >= 0)
		{
			
			tests = tests + 1;
			total = (score + total);
			cin >> score;
			
		}

		avg = (total / tests);
		
		if (avg > 90)																					// Grading Scale
			cout << endl << name << ", your grade is an A with a score of " << avg << endl;

		else if (avg > 80 && avg <= 90)
			cout << endl << name << ", your grade is a B with a score of " << avg << endl;

		else if (avg > 67.5 && avg <= 80)
			cout << endl << name << ", your grade is a C with a score of " << avg << endl;

		else if (avg > 55 && avg <= 67.5)
			cout << endl << name << ", your grade is a D with a score of " << avg << endl;

		else if (avg >= 0 && avg <= 55)
			cout << endl << name << ", your grade is an F with a score of " << avg << endl;
		else
			cout << endl << "You didn't enter any scores." << endl;

		cout << endl <<
			"=======================================================================" << endl;
		
		cin.clear();

		cout << "Type your name (press ENTER to terminate) : " << endl;
		getline(cin, name);
		cin.ignore(128, '\n');

	} while (name.length() != 0);

	cout << "No name was entered!";

	cout << endl << "Goodbye";
	cin.get();

	return 0;
}
Topic archived. No new replies allowed.