G+_Sandrine Marquis Posted April 8, 2015 Share Posted April 8, 2015 I have a question. I'm programming on Arduino. I have a function with some parameters and it's suppose to return a value. And it's giving me an error when I compile it. it refuse to compare a value from an array of INT with a INT variable. see code below and errors messages. int calculChange(int Mode, int operatorChoice, int value1){ int newValue = 0; int matrix[7][4] = { {0,0,0,0}, {24,-1, 0, 23}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0.0,0,0} }; if (operatorChoice == 1) { value1++; if (value1 == matrix[mode][0]) { newValue = matrix[mode][2]; } } else if (operatorChoice == 2) { value1--; if (value1 == matrix[mode][1]) { newValue = matrix[mode][3]; } } return newValue; } errors : Arduino: 1.6.3 (Linux), Board: "Arduino Uno" clk1.ino: In function 'int calculChange(int, int, int)': clk1.ino:447:34: error: invalid types 'int [7][4][string [6]]' for array subscript clk1.ino:448:33: error: invalid types 'int [7][4][string [6]]' for array subscript clk1.ino:452:34: error: invalid types 'int [7][4][string [6]]' for array subscript clk1.ino:453:33: error: invalid types 'int [7][4][string [6]]' for array subscript Error compiling. Link to comment Share on other sites More sharing options...
G+_Ben Reese Posted April 8, 2015 Share Posted April 8, 2015 How are you calling the function? It looks like the function is being passed a string where it expects an int... Maybe. Link to comment Share on other sites More sharing options...
G+_Sandrine Marquis Posted April 8, 2015 Author Share Posted April 8, 2015 I'm not calling the function yet. So, I'm not passing anything yet. I'm writing this function because I want to replace repetitive code. Link to comment Share on other sites More sharing options...
G+_610GARAGE Posted April 8, 2015 Share Posted April 8, 2015 You are use variable "mode", but I don't see it declared. Is it supposed to be "Mode"? if (operatorChoice == 1) { value1++; if (value1 == matrix[mode][0]) { newValue = matrix[mode][2]; } } else if (operatorChoice == 2) { value1--; if (value1 == matrix[mode][1]) { newValue = matrix[mode][3]; } } Link to comment Share on other sites More sharing options...
G+_Sandrine Marquis Posted April 8, 2015 Author Share Posted April 8, 2015 I will into it. I'm not sure if it an error on my post only or also in my original code. Link to comment Share on other sites More sharing options...
G+_Dan Salter Posted April 8, 2015 Share Posted April 8, 2015 You have a . not a , in the last line of the array declaration. Link to comment Share on other sites More sharing options...
G+_Sandrine Marquis Posted April 8, 2015 Author Share Posted April 8, 2015 Thx. Both errors were in my original code and sorry for bothering you with dummy questions. Works fine now. Link to comment Share on other sites More sharing options...
G+_Ben Reese Posted April 8, 2015 Share Posted April 8, 2015 Yeah, it definitely makes sense to put repetitive code into its own function. Glad you got it figured out! I saw the same problem with the Mode when it didn't compile. The . vs , probably wouldn't appear until you tried running it. Link to comment Share on other sites More sharing options...
G+_Dan Salter Posted April 8, 2015 Share Posted April 8, 2015 Not a problem! It's always worth getting a 2nd set of eyes over a problem :o) Link to comment Share on other sites More sharing options...
Recommended Posts