Two-dimensional Array. Inputting the arrays into the code

I am trying to create a program that allows the user to input 6 quiz grades for x number of students. X being up to 300 students. you also have to be able To compute the class average on a specific quiz, see the letter grade of a specific student, and compute the overall class average in the course.

this is what ive been able to do so far, however i am unsure as if i should make a function to calculate the average of the quizzez, and if i do how should i link the variable in the for loop that is number_of_students to the function.

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

using namespace std;

void menu();
float quiz_avg();



int main()
{ 
	char choice;
	char ans = 'N';
	char y;
	int number_of_students,x;
	float grades[300][6];
	char input;



	do
	{
		menu();
		cin>> input;

		if (input == '1')
		{
			cout<<"Please give a value for number of students:"<<endl;
			cin>> number_of_students;
			for (int i = 0; i < number_of_students; i++)
			{
				for (int j = 0; j < 6; j++)
				{
					cout<< "grade of student "<< i+1 << " for quiz " << j+1 <<endl;
					cin>> grades[i][j];



				}
			}
			menu();
			cin>> input;
			if (input=='1')
				cout<< "please restart the application to enter new scores"<<endl;
			else if (input!='1-4')
				cout<< "invalid choice. only options 0-4 are allowed"<<endl;
			else if (input ==2)
			{
				cout<< "Give the number of the quiz ";
				
				cin>> x;

			}
		}

		else if (input =='2')
			cout<< "No scores inputed"<<endl;
		else if (input =='3')
			cout<< "No scores inputed"<<endl;
		else if (input =='4')
			cout<< "No scores inputed"<<endl;
		else if (input>'4')
			cout<< "Wrong choice. Only options 1-4 are available."<< endl;

		if (input=='0')
		{
			cout<<"are you sure you wish to exit? (Y/N)"<< endl;
			cin>> ans;
		}
		else if (input<'1')
			cout<< "Wrong choice. Only options 1-4 are available."<< endl;
	}
	while (ans !='y'&& ans != 'Y');
	system("pause");

	return (0);
}


void menu()
{
	cout<< "Student project Database"<< endl;
	cout<<endl<<endl;
	cout<< "Please choose an option"<<endl;
	cout<<"1. To store the scores for a students quizzez"<< endl;
	cout<<"2. To compute the class average on a specific quiz"<< endl;
	cout<<"3. To see the letter grade of a specifit student" <<endl;
	cout<<"4.To compute the overall lass average in the course"<< endl;
	cout<<"Press 0. To quit"<<endl;
	cout<<"Please make a choice;"<<endl;
}

Last edited on
An average would be the total points achieved by all students on a quiz divided by the number_of_students. You could make this a separate function. I might even split out some of your other processing into separate functions.

I'd probably validate that they don't enter a number greater than 300 for the number of students, to prevent the program from going out of bounds on the array.
Topic archived. No new replies allowed.