Danger, Will Robinson! Guess row and column index


#1

This line doesn't seem right to me: board[guess_row][guess_col] = "X"

Shouldn't it be : board[guess_row -1][guess_col-1] = "X" ? The X is being placed based on the indexes number, instead of by the number being input. In order to convert the index to the number input don't we have to subtract by 1? For example, without subtracting 1, when I enter row as 2 and column as 5, the X is plotted at 3,5 (the index 2,5). What am I not understanding?


#2
 ----- ----- ----- ----- -----
| 0,0 | 0,1 | 0,2 | 0,3 | 0,4 |
 ----- ----- ----- ----- -----
| 1,0 | 1,1 | 1,2 | 1,3 | 1,4 |
 ----- ----- ----- ----- -----
| 2,0 | 2,1 | 2,2 | 2,3 | 2,4 |
 ----- ----- ----- ----- -----
| 3,0 | 3,1 | 3,2 | 3,3 | 3,4 |
 ----- ----- ----- ----- -----
| 4,0 | 4,1 | 4,2 | 4,3 | 4,4 |
 ----- ----- ----- ----- -----

The time to subtract 1 is from the inputs. That way the rest of the code can stay as written without making adjustments. Just be sure to tell the user what to enter.


#4

I agree with systemslayer36115, but mtf's suggestion works as well. The trouble is that mtf's option works without error, but systemslayer36115's option gives an error even though they both work. Perhaps this is something that can be addressed about the courseware?


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.