Help with modulo equation

Here is a portion of my code

 private void DrawRow(Graphics paper, int boardSize, int rowNum, int yPos) { int xPos = 0; for (int colNum = rowNum; colNum <= boardSize; colNum++) { if(rowNum + colNum % 2 == 0) { DrawSquare(paper, xPos, yPos, LightBrown); } else { DrawSquare(paper, xPos, yPos, DarkBrown); } xPos += SQUARE_WIDTH; } 

all variables are declared properly. When i set rowNum = 0, i get the alternating colors like i want but there is always an extra square (boardSize = 5, there will be 6 squares)

So if i set rowNum = 1 i get 5 squares when boardSize = 5 but they dont alternate in color (always goes with the else). What i think is happening is that the if statement isnt adding colNum and rowNum then doing modulus on it. when i add brackets if(rowNum + colNum) %2 ==0)) i get red line error…

what am i doing wrong?

by theplaymaker626 via /r/csharp

Leave a Reply