Array help

Hello, I am nearly finished with this assignment, except, for the part where I need to get the letter grade. I have an array that stores each of the scores for each student but I am unsure on how to go about finding the letter grade equivalent of each averaged grade for each student. Here is the code I have so far. It is working great, but I am unsure on how to implement a way of finding the letter for each score.

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
 # include <iostream>
# include <string>
using namespace std;

int sum(int score[]) //Adds together the three scores for each student.
{
	int sum = 0;
	for (int i = 0; i < 3; i++)
	{
		sum += score[i];
	}
	return (sum / 3);
}

int main()
{
	int studentNum = 0;
	int studentScores = 0; // The score for each student before it is averaged
	int numScores = 3;	//The amount of scores to average together for each student.

	cout << "How many students do you need to record information for?" << endl;
		cin >> studentNum;


	//---------------------------------------------------------------------------- Arrays
	string studentName[studentNum]; //Array that holds each of the students names.
	int studentId[studentNum]; //Array that holds each of the students id numbers.
	int studentScore[studentNum][numScores]; //Array that holds each of the students three scores.
	//----------------------------------------------------------------------------End of Arrays


	cout << "Enter the name for each student below. " << endl; //Gets the name of each of the students.
	for (int i = 0; i<studentNum; i++)
	{
		cout << "Enter the name of the student " << i + 1 << ". -> ";
		cin >> studentName[i];
	}


	for (int i = 0; i < studentNum; i++) //Gets the id number for each of the students.
	{
		cout << "Enter the student id for " << studentName[i] << endl;
		cin >> studentId[i];

	}


	cout << "Please enter the three scores for each of the students." << endl; //Gets the 3 test scores for each of the students.

	for (int i = 0; i < studentNum; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			cout << studentName[i] << ": ";
			cin >> studentScore[i][j];
		}
	}



	for (int i = 0; i<studentNum; i++) //Displays the name and id number of each student.
	{
		cout << "Student Name: " << studentName[i] << endl << "ID: " << studentId[i] << endl << "Students Scores: " << sum(studentScore[i]) << endl;
	}

}

	

Thanks for any help or advice you can give.
-Torm04
Last edited on
Like so:
1
2
3
4
5
6
7
8
9
10
11
12
char GetLetter(int avg)
{
  if(avg > 90)
    return 'A';
  else if(avg > 80)
    return 'B';
  else if(avg > 70)
    return 'C';
...
  else
    return 'X';
}
Thanks so much for the answer coder777. I got it finished. THANKS
Topic archived. No new replies allowed.