1. Get students ID (1-10) and their test score (0-100) for 10 students using two dimensional array. This should be in a function call GetInput.
2. Create a function that calculate the average of class and print.
3. The last item in the array should store sum and average.
int student_record[11][2], student_record[10][0] should have sum and student_record[10][1] should have average.
4. Make sure you print out all student's ID and score in nice formatted text. And, print the average at the bottom.
ignoring the function get input and stuff, i want to know how i will get the sum of the student score in
sorry my wording was a bit wrong. i meant to say how would i add the sums up and find the average then place it in student_record[10][0] and student_record[10][1].
for example:
11 is too much so lets say student_record[4][2]
and this is my array chart
0 1
0 0 20
1 1 30
2 2 40
3 SUM AVERAGE
basically i want to add up the entire 1 column ( [0][1] , [1][1] , [2][1] ) and place it in sum. i then want to divide them by the number i added and place it inaverage.
To iterate through an array you can use a for loop.
Create a variable to store the sum
Loop through the rows of column 1 and add the number to the total each time
EDIT: now that I think about it the average will be stored as an int. If your total isn't exactly a multiple of the number of students the average score will be wrong
I wanted to avoid doing the assignment for you, but I can't explain it without an example
To loop through a 2D array you do exactly what you do to loop through a 1D array. Since the column of the grades is always the same you only need to change the index for the row
1 2 3
int total;
for(int i = 0; i < students; ++i)
total += array[i][1];
As you can see, at each cycle you will be adding value array[0][1], array[1][1], array[2][1], etc... to the total of the grades
The array is 2D but you don't iterate in two dimensions. TO do that you would do something like
1 2 3 4
for(int i = 0; i < rows; ++i)
for(int j = 0; j < columns; ++j)
something += array[i][j];