Student Grade Book

Hi everyone! I'm new to C++ programming. I need to write a program that reads five student's test grade from four different tests. Each student's name and test score are initialized in arrays.And then, get average grade for each student. After that, print out each student's letter grade. Here is the code I wrote:
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
#include <iostream>
using namespace std;
const int NUM_STU=5, NAME_SIZE=20, NUM_TESTS=4;

void computeAverage(double [][NUM_TESTS], double [], int, int);	
							// tests, average, NUM_STUDENTS, NUM_TESTS
void letterGrade(double [], char [], int);		// average, grade, NUM_STUDENTS
void displayGrade(char [][NAME_SIZE], char [], int);	// names, grade, NUM_STUDENTS

int main()
{	
	char names[NUM_STU][NAME_SIZE] = 
			{"Troy Barnes","Abed Nadir","Annie Edison","Britta Perry","Jeff Winger"};
	double tests[NUM_STU][NUM_TESTS] =
			{{50, 60, 70, 80}, {60, 70, 80, 90}, {70, 80, 90, 100}, 
			{80, 90, 100, 100}, {90, 100, 100, 100}};
	double average[NUM_STU];			// average score
	char   grade[NUM_STU];			// letter grade

	computeAverage(tests, average, NUM_STU, NUM_TESTS);
	letterGrade(average, grade, NUM_STU);
	displayGrade(names, grade, NUM_STU);
	system("pause");

	return 0;
}

void computeAverage(double tests[][NUM_TESTS], double average[], int num_stu, int num_tests)
{
	double sum = 0;
	for (int i=0;i<NUM_STU;i++)
	{
		for (int j=0;j<NUM_TESTS;j++)
		{
			sum+=tests[i][j];
			average[i]=sum/NUM_TESTS;
		}

	}
}

void letterGrade(double average[], char grade[], int num)
{
	for (num=0;num<NUM_STU;num++)
	{
		if (average[num] < 60) 
		grade[num] = 'F';
		else if (average [num] < 70) 
		grade[num] = 'D';
		else if (average [num] < 80) 
		grade[num] = 'C';
		else if (average [num] < 90) 
		grade[num] = 'B';
		else if(average [num] <= 100) 
		grade[num] = 'A';
	}
}

void displayGrade(char names[][NAME_SIZE], char grade[], int num) 
{
	for (num=0; num<NUM_STU; num++)
	{
		cout <<"Student Name: "<<names[num]<<endl;
		cout <<"Student's Letter Grade: "<<grade[num]<<endl;
	}
}

It works but it only displays first student's grade. Can anyone tell me what did I do wrong? Thank you!
well do you have any sort of a loop? right now all it does is run through once because you didnt tell it to go back to the beginning
Topic archived. No new replies allowed.