mercredi 1 avril 2020

C++ Counter not resetting after each line

I am a student new to C++, and I am confused why my counter is not resetting and is resulting in everyones grade being the same as they are adding up as one big one. Can you guys please help guide me in the right direction. Thanks

Here is an example of what I mean

Student 0 has a score of 47/10
Student 1 has a score of 47/10
Student 2 has a score of 47/10
Student 3 has a score of 47/10
Student 4 has a score of 47/10
Student 5 has a score of 47/10
Student 6 has a score of 47/10
Student 7 has a score of 47/10

#include <iostream>
using namespace std;

/*
Key to the Questions
0 1 2 3 4 5 6 7 8 9
D B D C C D A E A D
*/
int main()
{
    const int ROWS = 8;                             // Answer key
    const int COLS = 10;        // D    B    D    C    C    D    A    E    A    D
    char letters[ROWS][COLS] = { {'A', 'B', 'A', 'C', 'C', 'D', 'E', 'E', 'A', 'D'}, // 7
                                {'D', 'B', 'A', 'B', 'C', 'A', 'E', 'E', 'A', 'D'}, // 6
                                {'E', 'D', 'D', 'A', 'C', 'A', 'E', 'E', 'A', 'D'}, // 5
                                {'C', 'B', 'A', 'E', 'C', 'A', 'E', 'E', 'A', 'D'},
                                {'A', 'B', 'E', 'C', 'C', 'A', 'E', 'E', 'A', 'D'},
                                {'B', 'B', 'C', 'C', 'C', 'A', 'E', 'E', 'A', 'D'},
                                {'B', 'B', 'C', 'C', 'C', 'A', 'E', 'E', 'A', 'D'},
                                {'E', 'B', 'C', 'C', 'C', 'A', 'E', 'E', 'A', 'D'} };

    const char ANSWERKEY[COLS] = { 'D', 'B', 'D', 'C', 'C', 'D', 'A', 'E', 'A', 'D' };

    // Loop for displaying submissions
    /*for (int row = 0; row < ROWS; row++)
    {
        for (int col = 0; col < COLS; col++)
        {
            cout << letters[row][col] << " ";
        }
        cout << endl;
    }*/

    // Loop for calculating score
    int studentNum = 0;
    for (int stu = 0; stu < ROWS; stu++)
    {
    int studentScore = 0;

    for (int count = 0; count < COLS; count++)
        {
            if (letters[0][count] == ANSWERKEY[count])
            {
            studentScore++;
            }
            if (letters[1][count] == ANSWERKEY[count])
            {
            studentScore++;
            }
            if (letters[2][count] == ANSWERKEY[count])
            {
            studentScore++;
            }
            if (letters[3][count] == ANSWERKEY[count])
            {
            studentScore++;
            }
            if (letters[4][count] == ANSWERKEY[count])
            {
            studentScore++;
            }
            if (letters[5][count] == ANSWERKEY[count])
            {
            studentScore++;
            }
            if (letters[6][count] == ANSWERKEY[count])
            {
            studentScore++;
            }
            if (letters[7][count] == ANSWERKEY[count])
            {
            studentScore++;
            }

        }

    //Display the results
        cout << "Student " << studentNum << " has a score of " << studentScore << "/10" << endl;
        studentNum++;
        studentScore = 0;
    }

    return 0;
}

Aucun commentaire:

Enregistrer un commentaire