0

I'm in the middle of implementing the init function in fifteen, but I ran into the error "error: array type 'int [9]' is not assignable" while compiling the program. What exactly does that mean?

Here is the relevant code:

// while i < user inputted dimensions
for (int i = 0; i < d; i++) {
    // nested loop for cols
    for (int j = 0; j < d; j++) {
        // sets rows so if d = 3 and i = 1, board[i] = 3
        board[i] = d * i;
        // sets cols so if d = 3 and i = 1 max number is 8 (3 * 3 - 1 = 8) - 1 
        board[j] = ((d * d) - 1) - i; 
        // numbers for board  (7-3 = 4 when i=1, d=3)
        board[i][j] = board[j] - board[i];
    }

}
4
  • I don't think all of the relevant text is posted. Is there a line in your code that contains int [9]? Or are you using int as a variable name? (int is a variable type. It's a bad practice to use that or other keywords as variable names. )
    – Cliff B
    May 25 '16 at 23:38
  • @CliffB I am not using any variables besides 'i', 'j' , 'd', and array 'board' (the last two are global and came with the pset). The above chunk is the only change I have made in the program.
    – David M
    May 26 '16 at 1:38
  • I don't see anything in the posted code that would generate the error you described. What line did the compiler say generated the error?
    – Cliff B
    May 26 '16 at 3:48
  • @CliffB board[i] = d * i; and board[j] = ((d * d) - 1) - i;
    – David M
    May 26 '16 at 10:15
0

I was looking at the error when I should have been looking at the code. Thought it was something completely different. The problem is that you have a two dimensional array and are writing assignments that only reference one dimension. When trying to assign a value to an array element, both dimensions must be specified. Otherwise you get the errors that you're seeing.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

1
  • How would I specify both dimensions?
    – David M
    May 27 '16 at 1:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .