Something is wrong with my loop....

I have been given an assignment to code a program that will calculate student's average's and overall average's. I am copying and pasting the word-for-word teacher given assignment:

Your problem is to develop a program to calculate grades and do a report given the following specifications:
Part 1: At the beginning of the program you will ask the user the name of the course you are working with and the number of exams and the number of programs that each student has done. Each test is worth 100 points and each program worth 15.
Part 2: Establish an output (printer) file. Name your output file "grades.dat" Start with outputting a heading showing the name of the class and column headings for "Name", "Test Avg", "Program Avg", "Final Avg", "Letter Grade"
Part 3: Get the name of a student and the test and program information for this student from keyboard input. The test information should be read in a loop and the total points calculated. The program information should also be inputed and summed with a loop.
Part 4: Calculate the students average with the tests counting as 80% of the final average and the programs counting 20%.
Part 5: Print the students information to the output file.
Part 6: Keep a running total of Final Average Points
Part 7: Loop as appropriate to work with multiple students. Determine how we will know when we have reached the end of our student list.
Part 8: After working with all students, calculate the class average and print this average, with appropriate labeling, to your output file.
Part 9: Do appropriate formatting to make the screen and the datafile output be neat. Use spacing and clearing of the screen as appropriate.

The code I attach is what I have figured out so far, but I can't get the loop to work correctly. It works perfectly the second time, but after it asks for the second student, it repeatedly asks for the same name. Any help will be appreciated. Thank you.

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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>

using namespace std;

string courseName, studentName;

int testlimit, programlimit, studentlimit;

float testsum, testGrade, programGrade, programsum;
float programpointspossible, testpointspossible, testclassavg;
float programclassavg, overallclassavg, studentavg;
float studenttestavg, studentprogramavg, finalstudentavg;

char lettergrade;

ofstream outData;

int testcounter = 1;
int programcounter = 1;

int main()
{
	outData.open("grades.dat");
	
	cout << "What is the course name?" << endl;
	cin >> courseName;
	
	cout << "How many students are there?" << endl;
	cin >> studentlimit;
	
	cout << "How many tests are there?" << endl;
	cin >> testlimit;
	
	cout << "How many programs are there?" << endl;
	cin >> programlimit;
	
	int studentcounter = 1;
	
	while(studentcounter <= studentlimit)
	{
		
		cout << "What is the student's name?" << endl;
		cin >> studentName;
		studentcounter++;
	
		while(testcounter <= testlimit || programcounter <= programlimit)
		{	
			while(testcounter <= testlimit)
			{
				cout << "What is the test grade?" << endl;
				cin >> testGrade;
				testsum = testsum + testGrade;
				studenttestavg = testsum / testlimit;
				testcounter++;
			}
			while(programcounter <= programlimit)
			{
				cout << "What is the program grade?" << endl;
				cin >> programGrade;
				programsum = programsum + programGrade;
				studentprogramavg = programsum / programlimit;
				programcounter++;
			}
		}
	}
		
	finalstudentavg = (studenttestavg * .8) + (studentprogramavg * .2);
	
	if(finalstudentavg >= 90)
	{
		lettergrade = 'A';
	}
	else if(finalstudentavg >= 80 && finalstudentavg < 90)
	{
		lettergrade = 'B';
	}
	else if(finalstudentavg >= 70 && finalstudentavg < 80)
	{
		lettergrade = 'C';
	}
	else if(finalstudentavg >= 60 && finalstudentavg < 70)
	{
		lettergrade = 'D';
	}
	else if(finalstudentavg < 60)
	{
		lettergrade = 'F';
	} 	
		setprecision(2);
	
		outData << setw(10) << left << setfill(' ') << "Name";
		outData << setw(15) << left << setfill(' ') << "Test Average";
		outData << setw(17) << left << setfill(' ') << "Program Average";
		outData << setw(15) << left << setfill(' ') << "Final Average";
		outData << setw(15) << left << setfill(' ') << "Letter Grade";
		outData << endl;
		outData << setw(10) << left << setfill(' ') << studentName;
		outData << setw(15) << left << setfill(' ') << studenttestavg;
		outData << setw(17) << left << setfill(' ') << studentprogramavg;
		outData << setw(15) << left << setfill(' ') << finalstudentavg;
		outData << setw(15) << left << setfill(' ') << lettergrade;
	
testpointspossible = (testlimit * 100);
programpointspossible = (programlimit * 15);

testclassavg = (testsum / testpointspossible);
programclassavg = (programsum / programpointspossible);

overallclassavg = ((testclassavg * .8) + (programclassavg * .2));

	outData << endl << endl;
	outData << "The class test average is " << testclassavg << '.';
	outData << endl;
	outData << "The class program average is " << programclassavg << '.';
	outData << endl;
	outData << "The overall class average is " << overallclassavg << '.';
	
	outData.close();
	
	return 0;
}

I think it's this part:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
		while(testcounter <= testlimit || programcounter <= programlimit)
		{	
			while(testcounter <= testlimit)
			{
				cout << "What is the test grade?" << endl;
				cin >> testGrade;
				testsum = testsum + testGrade;
				studenttestavg = testsum / testlimit;
				testcounter++;
			}
			while(programcounter <= programlimit)
			{
				cout << "What is the program grade?" << endl;
				cin >> programGrade;
				programsum = programsum + programGrade;
				studentprogramavg = programsum / programlimit;
				programcounter++;
			}
		}

Try changing the two inner while loops to if statements.
I'm sorry. I just tried that and it asks for a student name, then for a test grade, then for a program grade, and it did this 3 times each. After this it asked for the student's name the last 4 times. It needs to ask for total number of tests, programs, and students. It then should ask for a student's name, then the test grade for each test. Then, it should ask for the grades for each program for that student. It should repeat the process for a new student. Thank you for your input though. It let me see another way to go about coding.
Topic archived. No new replies allowed.