How to store user input?

I'm doing a type of calculator that uses a formula which needs 2 numbers from the user. My question is, how can I save a multiple variable integers(user inputs) in arduino? So arduino can execute the code/formula and do it's calculations.

Just for the references, the user will input the numbers using a 3x4 keypad and display on an 16x2 LCD screen

how can I save a multiple variable integers(user inputs) in arduino?

Save them in different variables or different elements of an array

May you please provide me with the code? I'd be so thankful to you. This is my first time in dealing with the C language.

CalcProject:
May you please provide me with the code? I'd be so thankful to you. This is my first time in dealing with the C language.

No

Have you looked at the examples that come with the Keypad library ?

I only have the keypad library from Adafruit, and this is the only code that comes with it:

#include "Adafruit_Keypad.h"

const byte ROWS = 4; // four rows
const byte COLS = 8; // eight columns
//define the symbols on the buttons of the keypads
byte trellisKeys[ROWS][COLS] = {
{1, 2, 3, 4, 5, 6, 7, 8},
{9, 10, 11, 12, 13, 14, 15, 16},
{17, 18, 19, 20, 21, 22, 23, 24},
{25, 26, 27, 28, 29, 30, 31, 32}
};
byte rowPins[ROWS] = {14, 15, 16, 17}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {2, 3, 4, 5, 6, 7, 8, 9}; //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad
Adafruit_Keypad customKeypad = Adafruit_Keypad( makeKeymap(trellisKeys), rowPins, colPins, ROWS, COLS);

void setup() {
Serial.begin(115200);
customKeypad.begin();

}

void loop() {
// put your main code here, to run repeatedly:
customKeypad.tick();

while(customKeypad.available()){
keypadEvent e = customKeypad.read();
Serial.print((int)e.bit.KEY);
if(e.bit.EVENT == KEY_JUST_PRESSED) Serial.println(" pressed");
else if(e.bit.EVENT == KEY_JUST_RELEASED) Serial.println(" released");
}

delay(10);
}

As far as I know any my understanding, it doesn't have the code that I need, or did I miss it among the lines?

The program you posted simply prints the value of the key that has been pressed. It does not save the data but it could be modified to do so

What keypad hardware do you have

Sorry for the late reply. My keypad hardware is exactly like the one in the picture, which I found from the internet. It's a 3x4 keyboard, and there's not any names or any model number.

keypad.png

For some reason I cannot open that file. Can you please provide a web link to the keypad

UKHeliBob:
For some reason I cannot open that file. Can you please provide a web link to the keypad

I can't open it too.

Sure, here's a link of a picture of the same type of my 3v4 keypad.

So, a 4 * 3 keypad

What is this all about in your code ?

const byte ROWS = 4; // four rows
const byte COLS = 8; // eight columns
//define the symbols on the buttons of the keypads
byte trellisKeys[ROWS][COLS] = {
  {1,  2,  3,  4,  5,  6,  7,  8},
  {9,  10, 11, 12, 13, 14, 15, 16},
  {17, 18, 19, 20, 21, 22, 23, 24},
  {25, 26, 27, 28, 29, 30, 31, 32}
};
byte rowPins[ROWS] = {14, 15, 16, 17}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {2, 3, 4, 5, 6, 7, 8, 9}; //connect to the column pinouts of the keypad

For a start, how many pins can you connect to that keypad ?

@CalcProject: there's a working example on Arduino Playground - Keypad Library , including the correct library for a 3x4 (!) keypad.

I already managed to run the keypad successfully. I just need to know how to assign the first input to the integer x1, then assign the next input to x2.

It all depends on the library you're using, and as far as I can see that's not the correct one for a 3 x 4 keypad! And please, answer UKHeliBob's question first.

I can connect 7 pins to my Keypad, and I'm using the Keypad.h library now, and I tried this example code which worked:

Keypad code:
#include <Keypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};

byte rowPins[ROWS] = {8, 7, 6, 5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {4,3,2}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup(){
// Robojax 4x3 keypad test
Serial.begin(9600);
Serial.println("Robojax 4x3 keypad");
}

void loop(){
// Robojax 4x3 keypad test
char key = keypad.getKey();
// just print the pressed key
if (key){
Serial.println(key);
}
// this checkes if 4 is pressed, then do something. Here we print the text but you can control something.
if (key =='4'){
// if key matches what you are looking for
Serial.println("Key 4 is pressed");
}

}

Looks good so far.

Now, how to save the numbers entered ?

First, when you get a keypress check whether it is in the range '0' to '9', ie whether it is a number or not. If it is then you need to add that digit to any previously received. You cannot simply add it though because firstly it is a character representing a number ('3' not 3) and not an actual number and secondly, suppose that the user had previously entered a '3' and now enters a '5' the number is not '8' but 35. How to deal with this ?

Set the variable for the sum of numbers entered to zero (not '0'). Do this only once
If the keypress is between '0' and '9' subtract '0' from it (sounds silly if you have never heard of ASCII codes)
Multiply the previous sum by 10
Add the keypress - '0' to the sum to get a new sum.
Keep reading keypresses until you get, say, '#' to signal the end of number entry.
The sum variable will now contain the first number

Use the same process to get the second number then do any calculations using the two numbers.