Help with if statements

My program is not going into the if statements I have setup in my function. I have used the Serial.print() to make sure the program is going into the function, it is. However the program is not going into the if statements.

Help would be appreciated.

void setup() {
Serial.begin(9600); //Open Serial monitor at 9600 baud rate, bits per second.
}
void loop() {
String name; //Declare a string varible.
String payGrade; //Declare a string varible.
String rank; //Declare a string varible.
Serial.println("Enter your name: "); //Prompt user for input.
while (Serial.available()==0){} //Wait for user input.
name = Serial.readString(); //Assign user input to a varible.
Serial.println("Enter your pay grade: "); //Prompt user for paygrade input.
while (Serial.available()==0){} //Wait for user input.
payGrade = Serial.readString(); //Assign user input to a varible.
convertPgToRank(payGrade, rank); //Run the function.
Serial.print(name);
Serial.println(rank);
}
String convertPgToRank(String payGrade, String &rank){ //Define function
  Serial.println(payGrade); // for troubleshooting only
  if (payGrade == "e1"){
    rank == "Pvt";
  }
    else if (payGrade == "e2"){
      rank == "PFC";
  }
    else if (payGrade == "e3"){
      Serial.println("in the else if statement");
      rank == "LCpl";
  }
    else if (payGrade == "e4"){
      rank == "Cpl";
  }
    else if (payGrade == "e5"){
      rank == "Sgt";
  }
    else if (payGrade == "e6"){
      rank == "SSgt";
  }
    else if (payGrade == "e7"){
      rank == "GySgt";
  }
    else if (payGrade == "e8"){
      rank == "MSgt";
  }
    else if (payGrade == "e9"){
      rank == "MGySgt";
  }
    else{
      rank == "Stolen Valor, not a real rank";
  }
}

Which if-statement do You refere to?
What printout do You get from

Serial.println(rank);
}
String convertPgToRank(String payGrade, String &rank){ //Define function
  Serial.println(payGrade); // for troubleshooting only

?

What does the curly bracket in this line of code do? It looks really odd to me.

String convertPgToRank(String payGrade, String &rank){ //Define function

Right now I am trying to get the following if statement to work by setting payGrade equal to "e3" over the serial monitor.
When payGrade == "e3"
"in the else if statement" does not print.

    else if (payGrade == "e3"){
      Serial.println("in the else if statement"); // This line is for troubleshooting only.
      rank == "LCpl";

}

A ; would look nornal. DEfining a function inside the code like that? I wouldn't try that.

Also, use autoformat! It gives a very informative display of the code.

Probably not the cause of your immediate problem but your function claims to return a String. It doesn't return anything.

Steve

Railroader:
What does the curly bracket in this line of code do? It looks really odd to me.

String convertPgToRank(String payGrade, String &rank){ //Define function

It starts the body of the function “convertPgToRank”.

Is this another line ending issue?

@rah1775

Other post/duplicate DELETED
Please do NOT cross post / duplicate as it wastes peoples time and efforts to have more than one post for a single topic.

Continued cross posting could result in a time out from the forum.

Could you take a few moments to Learn How To Use The Forum.
It will help you get the best out of the forum in the future.
Other general help and troubleshooting advice can be found here.

I believe the "&" sign I have in front of the variable on the following line of code makes the program return the value of the variable to the Void Loop. However, I did try the "return rank;" command at the end of the function and that did not change anything.

Thanks for the suggestion.

String convertPgToRank(String payGrade, String &rank){ //Define function

rah1775:
I believe the “&” sign I have in front of the variable on the following line of code makes the program return the value of the variable to the Void Loop.

It means that the variable is passed by reference, not value.