jeudi 8 juillet 2021

Why is my program failing to recognise this 'if' statement?

The purpose of this function is to increment values within a 12x12 array. At the end of each iteration of the function, one of the twelve rows and its corresponding column are eliminated (their values are replaced by an 'x').

In order to prevent the eliminated values from being incremented, I've added the condition (HMtable[i][n] < 9) into the 'if' statement. But for some reason, rather than skipping the eliminated values, the program just crashes (the command line goes blank, as though awaiting user input). Does anybody know why this might be occurring, and how to fix it?

for (i=0; i<12; i++)
        {
                quota = 1;
                while (quota > 0)
                {
                        n = rand() % 12;
                        if ((n != i) && (HMtable[i][n] < 9))
                        {
                                HMtable[i][n]++;
                                HMtable[n][i]++;
                                printf("HMtable[%d][%d] and HMtable[%d][%d] incremented\n", i, n, n, i);
                                quota--;
                        }
                }
        }

EDIT: I set the condition to '< 9' because the values in the array will never exceed nine due to the structure of the program, so in theory the only values that are greater than nine should be those which have been struck out (the ASCII value of 'x' is 120).

Aucun commentaire:

Enregistrer un commentaire