I'd recommend you look into std::vector.
On the first line after you check if (play = 1)
your main play area, you run a for loop using sizeof(setOrder)
without having put data into setOrder
first. Even if this did compile, logically your code would always skip the loop. Once you figure out vectors (which I'm pretty sure is what you're looking for), you might want to change this to checking the size of your setOrder
vector against a predefined maximum value (at which point the player wins?).
Here's a tutorial on vectors I found from google.
Also, a couple other possible mistakes/recommendations here:
- break your loop down into several sub-functions that you can call, so that reading your code isn't one giant block. This will also make it easier to find errors, as you can check that each function works, one function at a time.
- When you check
if (play = 1)
, you're actually using the assignment=
operator, not a conditional check==
. You're assigning the value of1
toplay
, instead of checking to see ifplay
is equal to1
. - You're using
sizeof(setOrder)
incorrectly.sizeof(X)
returns the number of bytesX
takes up, not necessarily the number of elements inX
. If you use a vector, there's a vector.size() function that returns the number of elements in the vector - Whem you check for the player's action, you call
analogRead(xAxis)
four times - once for each direction. The player's first input will always be checked in the first call. If it's false, the player will need to give another input to make it to the second if statement.