 # Problem with multiplying

Hi all,

I’m having trouble to multiply a char. I don’t know why, but it just outputs a number that is totally incorrect.

The point is to multiply the pressed key on the keypad times ten. But my code doesn’t work. For example, if I press 2 on the keypad I get 500.

Does somebody know what I did wrong?

Here’s my code:

``````#include <Keypad.h>
const byte ROWS = 4;
const byte COLS = 3;
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};

int test;
byte rowPins[ROWS] = {2, 3, 4, 5};
byte colPins[COLS] = {9, 10, 11};

void setup() {
Serial.begin(9600);

}

void loop() {
if (k != NO_KEY){
int test = k*10;
Serial.println(test);
delay(100);
}
}
``````

Thanks!

Jens

'2' == 50

50 * 10 == 500

What's the problem?

the char ‘2’ has ascii value 50
multiply that by 10 gives 500

change this

``````char k = keypad.getKey();
if (k != NO_KEY){
int test = k*10;
Serial.println(test);
delay(100);
}
}
``````

to

``````char k = keypad.getKey();
if (k != NO_KEY){
k = k - '0';         // change ascii value's to integer values
int test = k*10;
Serial.println(test);
delay(100);
}
}
``````

'2' = dec 50, x 10 = 500 http://www.asciitable.com/

try int test = (k-'0') *10; // convert from ascii & mult x 10

Thank you all now it works!