This function should check for a row, column or diagonal with all1\'s and if fou
ID: 3619011 • Letter: T
Question
This function should check for a row, column or diagonal with all1's and if found chenge them to all 2's but it doesn't work.int checkWinner ( int matches[][SIZE] )
{
int i, j, yes;
for( i = 0; i < SIZE; i++ )
{
yes = 1;
for( j = 0;j < SIZE; j++ )
{
if( matches[i][j] != 1 )
{
yes = 0;
j = SIZE + 5;
}
if( yes == 1)
for( j = 0; j < SIZE; j++ )
{
matches[i][j] = 2;
}
}
}
for( i = 0; i < SIZE; i++ )
{
yes = 1;
for( j = 0;j < SIZE; j++ )
{
if( matches[j][i] != 1 )
{
yes = 0;
j = SIZE + 5;
}
if( yes == 1)
for( j = 0; j < SIZE; j++ )
{
matches[j][i] = 2;
}
}
}
yes = 1;
for( i = 0; i < SIZE; i++ )
if( matches[i][i]!= 1 )
{
yes = 0;
i = SIZE + 5;
}
if( yes == 1 )
for( i = 0; i < SIZE;i++ )
{
matches[i][i] = 2;
}
yes = 1;
for( i = 0; i < SIZE; i++ )
if(matches[i][SIZE-i-i] != 1 )
{
yes = 0;
i = SIZE + 5;
}
if( yes == 1 )
for( i = 0; i < SIZE;i++ )
{
matches[i][SIZE-i-1] = 2;
}
return 0
}
Thanks!!
Explanation / Answer
x.P5lor="red">please rate - thanks I left my outputs in as comments, just in case more work is needed. the only problem I see is if both cards win, with the same number. It will report You as winner found is returning a code, as to what the winning line is. it can be change to be set to 1, instead of the code #include #include #include #include #include #define SIZE 5 #define SIZE_NUM_ARR 76 #define FLUSH while (getchar() != ' ') void fillCard ( int card[][SIZE] ); int linearSearch ( int card[][SIZE], int col, int target ); void printCard ( int card[][SIZE] ); int playGame ( int card1[][SIZE], int card2[][SIZE], int matches1[][SIZE], int matches2[][SIZE] ); int getNumber ( int chosenNumArray[] ); void displayNumber ( int currNum ); int checkForMatch ( int card[][SIZE], int matches[][SIZE],int ); int checkWinner ( int matches[][SIZE] ); void showWinner ( char nameStr[], int card[][SIZE], int matches[][SIZE] ); int continueFcn ( void ); void printmatches(int[][SIZE],int); int main (void) { srand(time(NULL)); int card1[SIZE][SIZE]; int card2[SIZE][SIZE]; int matches1[SIZE][SIZE]={0}; int matches2[SIZE][SIZE]={0}; int winner,i,j; do {for(i=0;iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.