So I'm trying to declare an array and assign values to it, and I can't figure out where my problem is.
Here's my code:
float wire_ohms[2][20];
wire_ohms[0][0] = 16; wire_ohms[1][0] = 5;
wire_ohms[0][1] = 18; wire_ohms[1][1] = 7;
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
And here's the compiler's error message:
array_test:5: error: 'wire_ohms' does not name a type
wire_ohms[0][1] = 18; wire_ohms[1][1] = 7;
^
exit status 1
What am I doing wrong here? The error tells me the last assignment doesn't have a type, but isn't the type defined when defining the array? I've never had such a hard time defining an array in any other language I've used, so I feel like I'm asking a stupid question here.
I am new to this.....and I have done assignment above 'setup' without compiler error and successful program execution (not saying that is proper, I may need to be educated LOL).
I think the compiler is telling you it wants to know what type your array variables are: i.e. byte, int, etc...
Well, this thread looks a lot different than it did a day ago..........
Delta_G:
Move those assignment lines into setup. You can't assign values like that at global scope. If you want to give initial values then you have to do it with an initializer list when you create the array.
Thanks Delta_G. Moving the assignment to setup() works, as in it compiles without errors.
But it's not really what I was looking for....
AWOL:
You've defined and initialised variables, but you haven't done assignments outside of any function.
So does the above statement mean that all assignments that happen after the array is defined must take place within a function? As in, any function, and not just in setup()?
I am only looking for answers and not to start the debate that has been removed from this thread. Really just looking to not have 20 assignment lines of code at the top of my program.