Two Dimensional Array help

Hi guys,

So each column represents a student, and the row represents the three students exam grades. What I'm trying to do is assign a user input student number to each student and then in the next portion I want to user input what index I want to display, for example I want [0][0] to display that array. Just an assignment for school and I feel as if I am totally lost on this because of the arrays. If someone could help me get started I would greatly appreciate it.

thanks

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

using namespace std;

int main ()

{	int student;
	int stud;
	int count;
	
	  
	int count[student] =
	{
	{ 87, 18, 77, 74 },
	{ 10, 35, 77, 5 },
	{ 58, 68, 35, 87 }  }
	  

	cin >> stud;
	for (int i = 0; i < 3; i++)    
	  { cout << "Student " << stud << ": "<< count[0][];
	  };
	  

	

	
	
}
closed account (48T7M4Gy)
This can be extended so you input a student and their results.

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

int main ()

{
    const int CLASS_SIZE = 3;
    const int NO_SUBJECTS = 4;
    
    int student_ID[CLASS_SIZE] = {1500, 1234, 9876};
    
    int results[CLASS_SIZE][NO_SUBJECTS] =
    {
        { 87, 18, 77, 74 },
        { 10, 35, 77,  5 },
        { 58, 68, 35, 87 }
    };
    
    for (int i = 0; i < CLASS_SIZE; i ++)
    {
        std::cout << "Student no: " << student_ID[i] <<  " Marks: ";
        
        for(int j = 0; j < NO_SUBJECTS; j++)
                std::cout << results[i][j] << ' ';
        
        std::cout << '\n';
    }
}


Student no: 1500 Marks: 87 18 77 74 
Student no: 1234 Marks: 10 35 77 5 
Student no: 9876 Marks: 58 68 35 87 
Program ended with exit code: 0
Last edited on
So if I extend this I can input the student number and my marks are assigned to the array, so I can input the index for the array and recieve that mark. Im going to give it a shot and see what I get.
closed account (48T7M4Gy)
Yes, your can. Don't forget that if you want to add more than 3 students you have to increase the CLASS_SIZE in my line 7. You can keep track of the current number in the class by a separate variable called say, 'count'.

Let us know how you get on.
Last edited on
Topic archived. No new replies allowed.