Please help me to display the inputted data in array
Go to solution
Solved by Vectorspace,
Your mistake is that you have a single Exam array that you are loading the scores into. Which means if you have two students, you fill the array with student 1's scores, then overwrite it with student 2's scores.
You need multiple scores arrays, one per student.
You can do this two ways:
#1: a 2-dimensional array. E.g.
int scores = new int[a][b]
when you access this array, e.g. scores[a] = 5 then a is the index for the student and b is the index for the score.
#2: Create a "Student" object, that contains a scores array. Then in your main function create an array of Student objects. This is what Slottr recommended
This is more complicated than option 1 but is the more correct approach. Better learning experience too.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now