EEPROM Assignment problems

Over the last week I have studied everything I could find about EEPROM and reading and writing to it the following program is returning unexpected values and after a week I still cant figure out where I am going wrong. The code is supposed to ask a user for a command and then execute either read or write to the EEPROM. I would appreciate any guidance, I know I must be missing something.

#include <EEPROM.h>

void setup()
{

Serial.begin(9600);{
while(!Serial);
; //wait

}
}
void loop()
{
int funct_One=0; // Buffer read var
int addr_One=200; // User input for address
int EEVal_One=0; // EEprom results
Serial.flush();
Serial.write(" Type the command to read or write to EEPROM \n ");//Print the directions to serial monitor
delay(10000);

for(int i=0;i<2;i++){

if(Serial.available() > 0){

funct_One=Serial.read();
Serial.println(funct_One);
}
if (funct_One==114)//Is read = to 114 the number for the word read??

{
Serial.print("Enter an address to read betwwen 0-1023 \n ");
delay(10000);
if (Serial.available() >0){
addr_One = Serial.read();
Serial.println(addr_One);
Serial.flush();

EEVal_One = EEPROM.read(addr_One);
Serial.write("The value at your memory address is " );
Serial.println(EEVal_One, DEC);
Serial.println();
Serial.flush();
}
break;
}
for (int x; x<=1; x++){
if(funct_One!=114){ //119 is the word write
int addr_Two;
int funct_Two;// var for code def
int val_One;

funct_One = funct_Two;
Serial.flush();
Serial.print("Please enter an address to write \n");
delay(10000);

if (Serial.available () >0){
addr_Two = Serial.read();
Serial.flush();
Serial.print( "Please provide a value less than 9999 to write \n" );

delay(10000);
}
if (Serial.available() >0) {

val_One=Serial.read();
Serial.flush();

EEPROM.write(addr_Two,val_One);
Serial.print("You have written a memory address of \n");
Serial.print((addr_One));
Serial.print(" with a value of ");
Serial.print((val_One));
} break;
}
}

Serial.end();

}

}

Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is that the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. If your browser doesn't show the posting toolbar then you can just manually add the code tags:
[code]``[color=blue]// your code is here[/color]``[/code]
Using code tags and other important information is explained in the How to use this forum post. Please read it.

Please always do a Tools > Auto Format on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read. If you're using the Arduino Web Editor you will not have access to this useful tool but it's still unacceptable to post poorly formatted code. I recommend you to use the standard IDE instead.

Please remove unnecessary blank lines from your code before posting to the forum. One or two to separate code into logical sections is fine but large spaces for no reason or random blank lines just make for more scrolling when we're trying to read your code.

DemonBadger:
the following program is returning unexpected values

That's not a sufficient description of the problem.

when I type in the word read on the serial monitor what is written to the variable funct_One is 114, when I type in the word write to the serial monitor what is written in the variable funct_One is 119,
then for some reason when the question gets asked in serial monitor to "enter and address it is 97
but the address in my code was hard coded to be EEPROM address 200, I wanted to see if there was some issue with Serial.read and because the variable is declared prior to the Serial.read somehow the variable retains the original value from when it was declared. I am extremely frustrated but not sure where I am going wrong. Am I missing a calculation or a function to convert data, is there a function call that is incorrect. I am prepared to learn it I just don't know what it is that I am missing or not understanding.

here is my code:

#include <EEPROM.h>

void setup()
 {

  Serial.begin(9600);{
  while(!Serial);
  ;              //wait
 
}
 }
void loop()
{
  int funct_One=0; // Buffer read var
  int addr_One=200; // User input for address
  int EEVal_One=0; // EEprom results
       Serial.flush();     
       Serial.write(" Type the command to read or write to EEPROM \n ");//Print the directions to serial monitor
       delay(10000);
       
    for(int i=0;i<2;i++){ 
      
  if(Serial.available() > 0){
    
    funct_One=Serial.read();
    Serial.println(funct_One);
  }
  if (funct_One==114)//Is read = to 114 the number for the word read??
  
    {
      Serial.print("Enter an address to read betwwen 0-1023 \n ");  
      delay(10000);  
     if (Serial.available() >0){
         addr_One = Serial.read();
         Serial.println(addr_One);
         Serial.flush(); 
       
         EEVal_One = EEPROM.read(addr_One);
         Serial.write("The value at your memory address is   " );
         Serial.println(EEVal_One, DEC);
         Serial.println();
         Serial.flush();
     }     
     break; 
    }
    for (int x; x<=1; x++){
  if(funct_One!=114){ //119 is the word write
  int addr_Two;
  int funct_Two;// var for code def
  int val_One;
  
  funct_One = funct_Two;
  Serial.flush();
  Serial.print("Please enter an address to write \n");
  delay(10000);

     if (Serial.available () >0){
      addr_Two = Serial.read();
  Serial.flush();   
  Serial.print( "Please provide a value less than 9999 to write  \n" );
 
 
   delay(10000);
     }    
  if (Serial.available() >0) {
    
    val_One=Serial.read();
    Serial.flush();
 
     EEPROM.write(addr_Two,val_One);
     Serial.print("You have written a memory address of \n");
     Serial.print((addr_One));
     Serial.print("  with a value of ");   
     Serial.print((val_One));
} break;
  }
}

Serial.end();

    }

}

pert:
Please always do a Tools > Auto Format on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read. If you're using the Arduino Web Editor you will not have access to this useful tool but it's still unacceptable to post poorly formatted code. I recommend you to use the standard IDE instead.

Please remove unnecessary blank lines from your code before posting to the forum. One or two to separate code into logical sections is fine but large spaces for no reason or random blank lines just make for more scrolling when we're trying to read your code.

here is my code:

#include <EEPROM.h>

void setup()
{

  Serial.begin(9600); {
    while (!Serial);
    ;              //wait

  }
}
void loop()
{
  int funct_One = 0; // Buffer read var
  int addr_One = 200; // User input for address
  int EEVal_One = 0; // EEprom results
  Serial.flush();
  Serial.write(" Type the command to read or write to EEPROM \n ");//Print the directions to serial monitor
  delay(10000);

  for (int i = 0; i < 2; i++) {

    if (Serial.available() > 0) {

      funct_One = Serial.read();
      Serial.println(funct_One);
    }
    if (funct_One == 114) //Is read = to 114 the number for the word read??

    {
      Serial.print("Enter an address to read betwwen 0-1023 \n ");
      delay(10000);
      if (Serial.available() > 0) {
        addr_One = Serial.read();
        Serial.println(addr_One);
        Serial.flush();

        EEVal_One = EEPROM.read(addr_One);
        Serial.write("The value at your memory address is   " );
        Serial.println(EEVal_One, DEC);
        Serial.println();
        Serial.flush();
      }
      break;
    }
    for (int x; x <= 1; x++) {
      if (funct_One != 114) { //119 is the word write
        int addr_Two;
        int funct_Two;// var for code def
        int val_One;

        funct_One = funct_Two;
        Serial.flush();
        Serial.print("Please enter an address to write \n");
        delay(10000);

        if (Serial.available () > 0) {
          addr_Two = Serial.read();
          Serial.flush();
          Serial.print( "Please provide a value less than 9999 to write  \n" );


          delay(10000);
        }
        if (Serial.available() > 0) {

          val_One = Serial.read();
          Serial.flush();

          EEPROM.write(addr_Two, val_One);
          Serial.print("You have written a memory address of \n");
          Serial.print((addr_One));
          Serial.print("  with a value of ");
          Serial.print((val_One));
        } break;
      }
    }

    Serial.end();

  }

}

I apologize for the poorly formatted code, I am trying to learn to code. Thank you for the advice on formatting I have implemented your suggestions here:

#include <EEPROM.h>
void setup()
{
  Serial.begin(9600); {
    while (!Serial);
    ;              //wait
  }
}
void loop()
{
  int funct_One = 0; // Buffer read var
  int addr_One = 200; // User input for address
  int EEVal_One = 0; // EEprom results
  Serial.flush();
  Serial.write(" Type the command to read or write to EEPROM \n ");//Print the directions to serial monitor
  delay(10000);
  for (int i = 0; i < 2; i++) {
    if (Serial.available() > 0) {
      funct_One = Serial.read();
      Serial.println(funct_One);
    }
    if (funct_One == 114) //Is read = to 114 the number for the word read??
    {
      Serial.print("Enter an address to read betwwen 0-1023 \n ");
      delay(10000);
      if (Serial.available() > 0) {
        addr_One = Serial.read();
        Serial.println(addr_One);
        Serial.flush();
        EEVal_One = EEPROM.read(addr_One);
        Serial.write("The value at your memory address is   " );
        Serial.println(EEVal_One, DEC);
        Serial.println();
        Serial.flush();
      }
      break;
    }
  }
    for (int x; x <= 1; x++) {
      if (funct_One != 114) { //119 is the word write
        int addr_Two;
        int funct_Two;// var for code def
        int val_One;
        funct_One = funct_Two;
        Serial.flush();
        Serial.print("Please enter an address to write \n");
        delay(10000);
        if (Serial.available () > 0) {
          addr_Two = Serial.read();
          Serial.flush();
          Serial.print( "Please provide a value less than 9999 to write  \n" );
          delay(10000);
        }
        if (Serial.available() > 0) {
          val_One = Serial.read();
          Serial.flush();
          EEPROM.write(addr_Two, val_One);
          Serial.print("You have written a memory address of \n");
          Serial.print((addr_One));
          Serial.print("  with a value of ");
          Serial.print((val_One));
        } break;
      }
    }
    Serial.end();
  }
  Serial.write(" Type the command to read or write to EEPROM \n ");//Print the directions to serial monitor
  delay(10000);

What if the users doesn't respond within 10 seconds?

Don't rely on delay

if (funct_One == 114) //Is read = to 114 the number for the word read??

The word "read" has four letters. It would come as four numbers. Google, "ASCII table" to see which numbers.

if (Serial.available() > 0) {
        addr_One = Serial.read();
        Serial.println(addr_One);

If you're getting input from the Serial monitor then you are getting things as ascii. You can't use that for addresses for EEPROM. You need to read in enough characters to cover the length of the number and convert from ascii to a real number with atoi.

Do you know what Serial.flush does? I'm guessing you don't. What do you think it does?

Why are you calling Serial.end? That's the one place where you need a flush and you don't have one.

Thank you for the comments,

With respect to the delay I would like to learn another way to wait for input from the user but nothing I have looked at provides me with an alternative. Is there a switch that will make the serial monitor wait, something I am missing?

funct_One variable outputs 114 when I ask the program to print the variable I have tried to match inputs to the ACSII table. I am just not sure where the data is coming from four letters "read" produces 114 in the program why?.

My understanding of serial flush is that it clears the serial buffer. Is this not correct?

DemonBadger:
My understanding of serial flush is that it clears the serial buffer. Is this not correct?

It only clears one of them. The outgoing buffer. It tells the program to stop and wait until everything you sent has finished sending.

DemonBadger:
funct_One variable outputs 114 when I ask the program to print the variable I have tried to match inputs to the ACSII table. I am just not sure where the data is coming from four letters "read" produces 114 in the program why?.

I don't know how you found that but it doesn't make any sense. i think you probably had some misunderstanding when you wrote whatever program told you that.

I would suggest you go read the Serial Input Basics thread.

thank you, I will read the serial inputs basics thread and see where that leads me. The 114 is what happen from the line 21-" serial.println funct_One" the result is 114.

DemonBadger:
thank you, I will read the serial inputs basics thread and see where that leads me. The 114 is what happen from the line 21-" serial.println funct_One" the result is 114.

Yes, 114 is what you got when you read once from Serial. So you only read the first letter. Please go look at an ascii table at what 114 means. I think it will suddenly make sense. 114 is a 'r'. So it is just the first letter of the word "read".

Ok, so the serial read is reading a byte, but I need it to read an array? So can I declare a global variable as a const byte of say 16. So the serial read function needs to be a serial.readBytes(16)