So do-while loop ignores nested while loop?

So, I am in a intro to C++ class right now. We are learning and working with loops and this is an assignment I did. Everything is fine, but I wanted an option to run the program again so I used a do-while loop to get a yes or no on running again. The thing is, when it runs again it ignores the whole second part of the program designed to get assignment scores. The test score section is a for loop and that runs fine every time. It's the while loop that is getting skipped.
Any suggestions are welcome and well received.

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
84
85
86
87
88
89
90
91
92
93
94
  #include <iostream>
#include <iomanip>
using namespace std;

int main()
{
	int quizGradeNumber, assignmentGradeNumber = 1;
	int quizGrade, assignmentGrade;
	double qGradeTotal = 0.0;
	double quizGradeAverage = 0.0;
	double aGradeTotal = 0.0;
	double assignmentGradeAverage = 0.0;
	char again;

	cout << "This program will accumulate your quiz and assignment scores\nto determin your grade. \n";
	cout << "First let me get some input... \n";
	cout << "\tQuizzes are worth 10 points. \n";
	cout << "\n";

	do
	{

		for (quizGradeNumber = 1; quizGradeNumber < 5; quizGradeNumber++)
		{
			cout << "\tEnter a grade for quiz # " << quizGradeNumber << ":  ";
			cin >> quizGrade;
			//Input validation!
			while (quizGrade < 0 || quizGrade >10)
			{
				cout << "Please use a number between 0 and 10.\t";
				cin >> quizGrade;
			}
			qGradeTotal += quizGrade;

		}
		cout << "\n";
		cout << "Quiz Grade Total = " << qGradeTotal << endl;
		quizGradeAverage = qGradeTotal / 4;
		cout << fixed << showpoint << setprecision(1);
		cout << "Quiz Grade Average = " << quizGradeAverage << endl;
		cout << "\n";

		cout << "\tAssignments are worth 20 points. \n";
		cout << "\n";

		while (assignmentGradeNumber < 9)
		{
			cout << "\tEnter a grade for assignment # " << assignmentGradeNumber << ":  ";
			cin >> assignmentGrade;
			//Input validation!
			while (assignmentGrade < 0 || assignmentGrade > 20)
			{
				cout << "Please use a number between 0 and 20.\t";
				cin >> assignmentGrade;
			}
			aGradeTotal += assignmentGrade;
			++assignmentGradeNumber;
		}
		cout << "\n";
		cout << "Assignment Grade Total = " << aGradeTotal << endl;
		assignmentGradeAverage = aGradeTotal / 8;
		cout << fixed << showpoint << setprecision(1);
		cout << "Assignment Grade Average = " << assignmentGradeAverage << endl;
		cout << "\n";

		float percentage = ((quizGradeAverage + assignmentGradeAverage) / 3) * 10;
		char letterGrade;

		cout << fixed << showpoint << setprecision(1);
		cout << "Overall percentage grade is = " << percentage << "% \n";

		if (percentage >= 90)
			letterGrade = 'A';
		else if (percentage >= 80)
			letterGrade = 'B';
		else if (percentage >= 70)
			letterGrade = 'C';
		else if (percentage >= 60)
			letterGrade = 'D';
		else
			letterGrade = 'F';

		cout << "The letter grade is = " << letterGrade << endl;
		cout << "\n";
		cout << "Would you like to run this program again? (Y/N) ";
		cin >> again;

	} while (again == 'Y' || again == 'y');

	cout << "Thanks for using this program.\n'Live long, and prosper.'\n";
	cout << "\n";
		system("pause");
		return (0);
}
You never reset the value of assignmentGradeNumber so the loop condition is already false when you reach the loop the second time.
I kind of thought that might be the culprit. so if i just put int assignmentGradeNumber = 1 inside the do loop everything will work out the way i want?
Okay, so I changed assignmentGradeNumber =1 to inside the do-while loop. The thing I'm encountering now is that qGradeTotal and aGradeTotal still have their values from the previous execution. Now I figure i could just define both as '0' before the loops initialize, but is there a better way to wipe out cin input at the end before it restarts? Sorry to ask so many questions, but my class is 1 4hr a week class and its execrated due to summer schedule so i don't get a lot of one on one for Q&A with the professor.
No variable (except again) are used outside the loop so you could just define them inside the loop instead. That way the variables will be initialized each time the loop (re)starts.
Topic archived. No new replies allowed.