two dimensional arrays

Suppose array quiz contains the answers to five true and false wuestions. The first row [0] contains the corrext answers to the array. Each row further contains a particular studens responses to the five questions on the quiz.

I must write down the necessary instructions to calculate and output each students score. How do I compare the arrays [1] and so forth to [0]?

This is what I think:

Const int NUMBEROFROWS = 6;
Const int NUMBEROFQUESTIONS = 5;
Char quiz[NUMBEROFROWS][NUMBEROFQUESTIONS]

For(int I = 0; I < NUMBEROFROWS; i++)
{
For(int j = 0; j < NUMBEROFQUESTIONS; j++)
{
Int score = 0;
If((quiz[I][j] == 'T' || quiz [I][j] == 'F') && (quiz[I][j] == quiz[0])
Score += quiz[I][j];
}
}

Cout << "Student 1: score" << score << endl;

I know this is wrong, can some1 please help me.
I do not understand this condition

If((quiz[I][j] == 'T' || quiz [I][j] == 'F') && (quiz[I][j] == quiz[0])

Do you need to count the number of 'T' in each column?
Well I'm not very gud in arrays so don't judge me, in array[0] is the right answers, so say in array [0] {'T', 'T', 'F', 'F', 'T'}, then you in the other arrays student answers should ne T or F answers, and if it is correct according to array[0], every answer u get a point if it is right or no point if answer is wrong.
So if you have the array

const int NUMBEROFROWS = 6;
const int NUMBEROFQUESTIONS = 5;
char quiz[NUMBEROFROWS][NUMBEROFQUESTIONS];

and a given row number you shall calculate how many columns coinsides in the given row with the first ((zero) row.

Let assume that the given row is n then you can write

1
2
3
4
5
int score = 0;
for ( int col = 0; col < NUMBEROFQUESTIONS; col++ )
{
   score += quiz[n][col] == quiz[0][col];
}


Or you can define an array of scores

1
2
3
4
5
6
7
8
9
int scores[NUMBEROFROWS - 1] = { 0 };

for ( int i = 1; i < NUMBEROFROWS; i++ )
{
   for ( int j = 0; j < NUMBEROFQUESTIONS; j++ )
   {
      scores[i - 1] += quiz[i][j] == quiz[0][j];
   }
}
Last edited on
Ok just a quick question, why do u say int scores[NUMBEROFROWS - 1]?
Because the first ((zero) row is reserved for correct answers as I have understood. So the number of scores will be one less than the total number of rows in quiz.
Last edited on
So if I have to output the score for student 1, would cout << "Student 1: score "<< score << endl, suffice? Or is it wrong? Or do u have to say << score[1] for the 1st student?
If you will define an array for students scores then the score of the first student is specified as scores[0]
Last edited on
Ok thanx, sorry about the stupid questions, I'm writting exams in three days, so I have to know how to do it.
Topic archived. No new replies allowed.