Comparing Serial.parseInt to subString.

Hello,
I am working on a sketch trying to use the serial monitor to enter some values using for loops. I want these values to be stored for comparison until they are changed again by entering new values into the serial monitor. The sketch starts up and prompts for values to be entered. The idea is these values could be compared to the String called inputString coming in from the software serial port. An example would be if the first 5 values were 100,200,300,400,500 and the inputString was “100 Test String”, then a comparison could be done using the int “header” and “ value[]”. Everything works well except the part
if ((header == values[0])||(header == values[1])||(header == values[2])
||(header == values[3])||(header == values[4]));
{
Serial.print ("header and value match");
This part of sketch always prints regardless of what inputString sends
I would appreciate help with this and also any suggestions on my code. Code is attached.

#include <SoftwareSerial.h>
     // software serial #1: TX = digital pin 2, RX = digital pin 3
    SoftwareSerial portOne(2, 3);
    const int NUMBER_OF_FIELDS = 5;
    int fieldIndex =0;
    int values [NUMBER_OF_FIELDS];
    const int NUMBER_OF_FIELDS2 = 5;
    int fieldIndex2 =0;
    int values2 [NUMBER_OF_FIELDS2];
    char inByte;
    String inputString = "";         // a string to hold incoming data
    boolean stringComplete = false;  // whether the string is complete
    int header;
    String stringOne, stringTwo;
 
  void setup() {
  // initialize serial:
    Serial.begin(9600);
    portOne.begin(9600);
    // reserve 200 bytes for the inputString:
    inputString.reserve(200);
    Serial.println ("To begin entering numbers for values 1-5");
    Serial.println ("Press the A key then enter room numbers.");
    Serial.println ("Numbers must be separated with a comma. Ex. A,100,200,300,400,500");
    Serial.println ("Press the Enter key when finished");
    Serial.println ('\r');
 }
   
  void loop() {
    while (Serial.available() > 0)
   {
    char inByte = Serial.read(); 
    if (inByte == 'A')
   {
    for (fieldIndex = 0; fieldIndex < 5; fieldIndex ++)
   {
    values[fieldIndex] = Serial.parseInt();
   }
   
    Serial.print ('\n');
    Serial.print(fieldIndex);
    Serial.println(" fields recieved:");
    //  for(int i=0; i < fieldIndex; i++)
   {
    Serial.print(values[0]);
    Serial.print(',');
    Serial.print(values[1]);
    Serial.print(',');
    Serial.print(values[2]);
    Serial.print(',');
    Serial.print(values[3]);
    Serial.print(',');
    Serial.print(values[4]);
    Serial.print ('\n');
    Serial.print ('\n');
    Serial.println ("To begin entering numbers for values 6-10");
    Serial.println ("Press the B key then enter room numbers.");
    Serial.println ("Numbers must be separated with a comma. Ex. B,100,200,300,400,500");
    Serial.println ("Press the Enter key when finished");
    
    
   }
   
    fieldIndex = 0;
   }
    
   
    if (inByte == 'B')
   {
    for (fieldIndex2 = 0; fieldIndex2 < 5; fieldIndex2 ++)
   {
    values2[fieldIndex2] = Serial.parseInt();
   }
    
    Serial.print ('\n');
    Serial.print(fieldIndex2);
    Serial.println(" fields2 recieved:");
    //  for(int i=0; i < fieldIndex; i++)
   {
    Serial.print(values2[0]);
    Serial.print(',');
    Serial.print(values2[1]);
    Serial.print(',');
    Serial.print(values2[2]);
    Serial.print(',');
    Serial.print(values2[3]);
    Serial.print(',');
    Serial.print(values2[4]);
    Serial.print ('\n'); 
    
   }
    fieldIndex2 = 0;
   }
    
  }

    // print the string when a newline arrives:
    if (stringComplete){
    Serial.println(inputString); 
    
   {
    char temp[5]; 
    inputString.substring(0,3).toCharArray(temp,sizeof(temp));
    header = atoi(temp);
    Serial.print ("header = ");
    Serial.println(header);
      
   }
    if ((header == values[0])||(header == values[1])||(header == values[2]) 
    ||(header == values[3])||(header == values[4])||(header == values[5]));   
    {
    Serial.print ("header and value match");// This part of sketch always prints regardless
   // of what inputString sends
    }
   
  
   }
    // clear the string:
    inputString = "";
    stringComplete = false;
   
    
    checkInput();
 }
   
  /*
   SerialEvent occurs whenever new data comes in the
   software serial RX.  This routine is run each
   time loop() runs, so using delay inside loop can delay
   response.  Multiple bytes of data may be available.
   */
  void checkInput() {
    while (portOne.available()) {
    // get the new byte:
    char inChar = (char)portOne.read(); 
    // add it to the inputString:
    inputString += inChar;
    // if the incoming character is a return, set a flag
    // so the main loop can do something about it:
    if (inChar == '\r') {
      stringComplete = true;
    } 
   }
  }

You seem to be declaring arrays of 6 elements but only prompting for and reading in 5 values. At the point you do the comparison, what is the value of 'header' and what are the values of 'values[0]' ... 'values[5]'?

Your are right. I changed the value of the array elements to 5. The values I have been using are for values[0] - [4] are 100,200,300,400,500. The value of header would be the first 3 charachters of inputString as long as they are digits. I have been trying any of the values numbers, 100 - 500 and also numbers that do not match the values, but the serial print always comes back as "header matches values". I think i'm missing something in the code.

Bicycler:
Your are right. I changed the value of the array elements to 5. The values I have been using are for values[0] - [4] are 100,200,300,400,500. The value of header would be the first 3 charachters of inputString as long as they are digits. I have been trying any of the values numbers, 100 - 500 and also numbers that do not match the values, but the serial print always comes back as "header matches values". I think i'm missing something in the code.

That wasn't my question.

In a scenario where the problem happens, what are the values of those variables at the point of the comparison? Not what you think the values ought to be, but the actual values?

PeterH,
I added a statement to print values[0] right after the println (header) and the values[0] displayed what I previously entered as the first number in the for lop statement, so I suspected my code was wrong somewhere. I ended up removing the semi colon just after the

if ((header == values[0])||(header == values[1])||(header == values[2])
||(header == values[3])||(header == values[4])||(header == values[5]));{
Serial.print ("header and value match");
This solved the problem.
Thanks, I appreciate your help.

if ((header == values[0])||(header == values[1])||(header == values[2])
        ||(header == values[3])||(header == values[4])||(header == values[5]));{   
     Serial.print ("header and value match");

What a mess.

bool match = true;
for(byte i=0; i<6; i++)
{
   if(header == values[i])
   {
      match = true;
      break;
   }
}
if(match)
{
     Serial.print ("header and value match");
}

While this is a bit more code, it is much easier to understand, and to expand, if the number of values ever changes.

It is also much easier to modify to determine which values[n] value header matches, if that ever becomes important.

Thank you, This does look like a better way.