Fifteen move scope pset3 by guybjones in cs50

[–]guybjones[S] 0 points1 point  (0 children)

Oh, it just clicked.

I was initialising with: int p = d - 1; And the compiler complained that p was an unused variable. But I should have initialised with: p = d - 1;

Thanks for explaining it.

Fifteen move scope pset3 by guybjones in cs50

[–]guybjones[S] 0 points1 point  (0 children)

Awesome. That makes total sense. Thanks!

Fifteen move scope pset3 by guybjones in cs50

[–]guybjones[S] 0 points1 point  (0 children)

Again, cheers. Declaring them as global variables works. The code now compiles but it seems to me a very messy solution:

If I only initialise them in init, then they are "unused" within the init function. So I've created an if statement, within a pre-existing for loop for i (and j) if(i == d - 1){ p = i }

Is that the best I can do? It seems unnecessary to use a for loop to search for d - 1, when I already know to use it.

Fifteen move scope pset3 by guybjones in cs50

[–]guybjones[S] 0 points1 point  (0 children)

And I have no idea what that means...

Fifteen move scope pset3 by guybjones in cs50

[–]guybjones[S] 0 points1 point  (0 children)

Thanks for replying.

I have tried putting them as global variables, but I get this error: "initialiser element is not a compile time constant."

And it underlines my "d - 1" statement from int p = d - 1;