Gradebook application

Okay, I borrowed (stole?) code from another post on here and modified it slightly. What I'm trying to do is input a student's name until the user types "Quit". After each entry I want it to display the student's name, average, and letter grade. Obviously my code isn't there yet...I am getting pieces right at a time. My main question at the moment is that after I type in "Quit" the program thanks the word quit is a student and asks for test scores and assigns an average and letter grade to it.

I know this program has a long way to go...Like I said, I'm piecing it together here, and I'm trying to fix problems as I run in to them. Below is what I have.

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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#include <iostream>
#include <string>
using namespace std;

// Declare structs
struct GradeBook{
	string name;		// Name of student
	int* tests;			// Pointer to an array of test scores
	double average;		// Average of test scores
	char grade;			// Grade for the course
};

// Function Prototype(s)
int inputStudents();				// Asks user for number of students
int inputTests();					// Asks user for number of test scores
int inputName();					// Asks uer for each student's name
int *inputScores(int);				// Asks user for the test scores for each student
double calcAverage(int*, int);		// Calculates the average test score for each student
char calcGrade(double);				// Calculates the letter grade for each student based on their average
void display(GradeBook*, int);		// Displays each student's name, ID#, average test score, and course grade
int counter = 0;                        //counter for number of students
string name;

int main(){

	// Create a dynamic array of the GradeBook structure. Array size is based upon user input given in
	// the inputStudents function. 
	GradeBook *studentList; 
	int size = inputStudents(); 
	studentList = new GradeBook[size];

	// Check for possible memory allocation errors. If error is found, end program. 
	if (studentList == NULL){
		cout << "Memory Allocation Error!";
		system("Pause");
		return 0;
	}

	// Create a variable array to hold the number of test scores for each student.
	int numOfTests = 3;   //inputTests();

	for (int count = 0; count < size; count++){
		//studentList[count].name = inputName();
		studentList[count].tests = inputScores(numOfTests);
		studentList[count].average = calcAverage(studentList[count].tests, numOfTests); 
		studentList[count].grade = calcGrade(studentList[count].average); 
	}

	display(studentList, size); 

	delete [] studentList; 

	system ("Pause");
	return 0;
}

int inputStudents(){

	int students; 
    //cout << "How many students are there?" << endl;
    //cin >> students; 
    counter = inputName();
    students = counter;

	return students; 
}

/*int inputTests(){

	int tests; 
	cout << "How many tests will there be?" << endl;
	cin >> tests;

	return tests;
}*/

int inputName(){

	//string name; 
	//counter = 0;
	if (name == "Quit")
		return counter;
		
	else while (name != "Quit")
		  {
	      cout << "Enter the student's name: ";                                               //sldkjf;sklafjskl;jfjkl
	      cin >> name;
	      ++counter;
		  }

	return counter;

}

int *inputScores(int numOfTests){

	int *scores; 
	scores = new int[numOfTests]; 

	cout << "Enter the test scores for the student. Press ENTER after each score." << endl;

	for (int count = 0; count < numOfTests; count++){
		cout << "Score " << (count + 1) << ": "; 
		cin >> scores[count];
	}

	return scores; 
}

double calcAverage(int *testScores, int numOfTests){

	int total = 0;  
	double average;

	for (int count = 0; count < numOfTests; count++){
		total += testScores[count];
	}
	
	average = total/numOfTests;
	return average;

}

char calcGrade(double average){

	char letterGrade; 

	if		(average > 90 && average <= 100)
		letterGrade = 'A';
	else if (average > 80 && average <= 90)
		letterGrade = 'B';
	else if (average > 70 && average <= 80)
		letterGrade = 'C'; 
	else if (average > 60 && average <= 70)
		letterGrade = 'D';
	else if (average >= 0 && average <= 60)
		letterGrade = 'F'; 
	else{  
		cout << "Logic error." << endl;
		// system("pause");
		exit(1); 
	}

	return letterGrade;
}

void display(GradeBook *studentList, int size){

	for (int count = 0; count < size; count++)
		cout << studentList[count].name << " " <<  " " 
		<< studentList[count].average << " " << studentList[count].grade << endl; 

	return; 
}
Just for starters the name can't be an int. it should be a string. Also, you need it to be quit or Quit. You need to compare the string.. quit or Quit. The name must be a string.
1
2
3
4
5
6
7
8
if (name == "Quit || quit)
		return counter;
		
	else while (name != Quit || quit)
cout<< Enter name: << THE variable <<"n\";
cin>> THE variable;

		  { 
Topic archived. No new replies allowed.