Replacing an integer in a 2D array with -1

It should print out a 20x20 array and then replace the numbers evenly divisible by 3 with a -1, it isn't.

what am I doing wrong?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <iostream>
#include <ctime>

using namespace std;

void fill2D(int grid[20][20]);
void printStatement(int grid[20][20]);
int createCoords(int grid[20][20]);
void fillLocations(int grid[20][20]);

int main()
{
	srand(time(0));
    
    int grid[20][20];
    
	fill2D(grid);
    createCoords(grid);
    fillLocations(grid);
	printStatement(grid);
	
    return 0;
}
void fill2D(int grid[20][20])
{
	for (int row = 0; row < 20; row++)
	{
        for (int col = 0; col < 20; col++)
        {
			grid[row][col] = rand() % 101;
        }
	}
}
void printStatement(int grid[20][20])
{
	for (int row = 0; row < 20; row++)
	{
        for (int col = 0; col < 20; col++)
        {
			cout << grid[row][col] << "\t";
        }
        cout << "\n";
	}
}
int createCoords(int grid[20][20])
{
	int booger[20][20];
    int count = 0;
    int coOrds = 0;
    
    
	for (int row = 0; row < 20; row++)
	{
        for (int col = 0; col < 20; col++)
        {
			if (grid[row][col] % 3 == 0)
			{
				booger[20][19] = coOrds;
                
				count++;
			}
        }
	}
	return coOrds;
}
void fillLocations(int &coOrds)
{
    for (int row = 0; row < 20; row++)
	{
        for (int col = 0; col < 20; col++)
        {
                if (coOrds % 3 == 0)
                    coOrds = -1;
        }
    }
}


Any help would be greatly appreciated.
You are not checking if the position in the array is equal to %3 ==0, you are checking if the variable coOrds is equal to the remainder of a division by three.
Topic archived. No new replies allowed.