Jump to content

I have a question I 'm programming on Arduino


G+_Sandrine Marquis
 Share

Recommended Posts

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

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

 Share

×
×
  • Create New...