Inbuilt EEPROM Isuses

Hello everyone, I am beginners for using arduino in-built EEPROM. I have a small doubt in this code.
in this code, I read a potentiometer value via PIN=A0. I read a push button signal via digital pin=4. My aim is, when I press the push button the corresponding value will be stored in internal EEPROM. After that, I want to get the value stored in EEPROM with the help of address. The address are provided via Serial monitor.

With the help of address the corresponding value stored in EEPROM will be display on the Serial monitor.
In this output I get a wrong value instead of stored value in internal EEPROM. I am using Arduino Uno Board.

Below I attached my program and output, kindly check it out,

#include <EEPROM.h>
int n, i = 0, p;

void setup() {
Serial.begin(9600);
pinMode(4, INPUT_PULLUP);
}

void loop() {
p = analogRead(A0);

if (digitalRead(4) == LOW) {
Serial.print("THE ADDRESS IS = ");
Serial.println(i);
Serial.print("THE VALUE OF POTENTIOMETER IS = ");
Serial.println(p);
EEPROM.put(i, p);
delay(4000);
i++;
}
if (Serial.available() > 0) {
Serial.println(“GET THE VALUE STORED IN EEPROM”);
n = Serial.parseInt();
Serial.print("THE GIVEN ADDRESS IS = ");
Serial.println(n);
Serial.print("THE VALUE STORED IN CORRESPONDING ADDRESS OF EEPROM IS = ");
Serial.println(EEPROM.get(n, p));
}
if(i==EEPROM.length()){
i=0;
}

}

THE OUTPUT IS,

THE ADDRESS IS = 0
THE VALUE OF POTENTIOMETER IS = 779
THE ADDRESS IS = 1
THE VALUE OF POTENTIOMETER IS = 1000
THE ADDRESS IS = 2
THE VALUE OF POTENTIOMETER IS = 672
THE ADDRESS IS = 3
THE VALUE OF POTENTIOMETER IS = 453
GET THE VALUE STORED IN EEPROM
THE GIVEN ADDRESS IS = 0
THE VALUE STORED IN CORRESPONDING ADDRESS OF EEPROM IS = -6133
GET THE VALUE STORED IN EEPROM
THE GIVEN ADDRESS IS = 2
THE VALUE STORED IN CORRESPONDING ADDRESS OF EEPROM IS = -14944
GET THE VALUE STORED IN EEPROM
THE GIVEN ADDRESS IS = 3
THE VALUE STORED IN CORRESPONDING ADDRESS OF EEPROM IS = 453

From the EEPROM.get() reference page:

Returns

A reference to the data passed in

Why would you want to print THAT?

The value that you read is in p, but you don't seem to care what that value is.

See my answer to your duplicate post in another thread.

Why would you want to print THAT?

The value that you read is in p, but you don't seem to care what that value is.

Thanks PaulS for your Reply. I read that value for my clarification if the data will be stored in EEPROM or Not.

I read that value for my clarification if the data will be stored in EEPROM or Not.

I don't understand that statement.

Before this statement:

  Serial.println(EEPROM.get(n, p));

Add

   p = 144;

After that statement, add

Serial.print("p = ");
Serial.println(p);

Correct the issue that the helicopter guy pointed out, and show us the new output.

Thanks @UNHeilBob, Now my program will work fine what I excepted.

I read that value for my clarification if the data will be stored in EEPROM or Not.

I don't understand that statement.

@PaulS, I wrote this program for my understanding.

Serial.print("p = "); Serial.println(p);

I will add that statement.