Nested Loops - Help!

Objective: Implement nested loops in a program to assign grades to students in a class at the end of a semester.

When entering the scores, if a student had an excused absence for a score it will be entered as -1. If a student has 2 or more excused absences, then do not compute the average and give the student a grade of I. If the student as less than 2 excused absences then compute the average and determine the grade. Of course for a student with 1 excused absence the average should not count the –1 score. For example, if the input scores for a student were 53, -1, 49 and 50, your program would ignore the -1, since this is the student’s only absence. or this student average will be (53+49+50)/3. The grade of S should be assigned if the student's average is 50.0 or above and U if it is below 50.0.

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
#include <iostream>

using namespace std;

int main()
{
	int numTests;
	char choice;

	cout << "Enter the ID and scores for each student. If a student has \n"
		"an excused absence then enter -1 for that score. " << endl << endl;
	cout << "Enter the number of scores for this semester:" << endl << endl;
	cin >> numTests;

	cout << "=========================================================" << endl;
	cout << "Add a student (Y to continue, any other character to end): ";
	cin >> choice;

	while (choice == 'Y')
	{
		int ID;
		cout << "Enter a student's ID: ";
		cin >> ID;

		double score, sum = 0, avgScore;
		int excused = 0, grade;
		for (int i = 0; i<numTests; i++)
		{
			// input score
			cout << "Enter a Score: ";
			cin >> score;

			// keep track of excuses
			if (score == -1)
			{
				sum = sum - score;
			}
			else
			{
				sum = sum + score; // only if score is >=0
			}

		}

		//avgScore = avgScore / (# of non-excused scores)
		avgScore = sum / numTests;


		if (avgScore > 50.0)
		{
			grade = 'S';
		}
		else if (avgScore < 50.00)
		{
			grade = 'U';
		}
		else
		{
			grade = 'I';
		}
		

		cout << "  ID=" << ID << "  Avg=" << avgScore << "  Grade=" << grade << endl;


		cout << "=========================================================" << endl;
		cout << "Add a student (Y to continue, any other character to end): ";
		cin >> choice;
	}

	system("pause");
	return 0;
}


What am I doing wrong that it won't take away the -1's that are entered or output the correct grade?
Topic archived. No new replies allowed.