title: C++ program if statements in function not executing. Seems Logically errored
body: <p>I am making a program in C++, that takes the user entered time in U.S. standard time and converts it to military time. The body of the main code is executing fine, but the problem comes in the body of my function beginning with the if statements. I am wondering why this is occurring; am fairly new with c++. Here's my code if you have question feel free to ask or need explanation of what the program is supposed to be doing. </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  using namespace std;
  
  void militaryConversion(string am_pmPart_st, string firstPartofTime, string secondPartofTime){
      // Converts they obtained strings, but first we must concatenate the two parts into one string
      string concatenatedTime;
      int militaryTime;
      cout &lt;&lt; "test1" &lt;&lt; endl;
  
      concatenatedTime = firstPartofTime + secondPartofTime;
      if(firstPartofTime == "12")
          {
          cout &lt;&lt; "Corresponding military time is: " &lt;&lt; concatenatedTime &lt;&lt; " hours" &lt;&lt; endl;
          }
  
      else if(am_pmPart_st == " am")
          {
              if (concatenatedTime.length() &lt; 4){
                  cout &lt;&lt; "Corresponding military time is: " &lt;&lt; concatenatedTime &lt;&lt; " hours"&lt;&lt; endl;
              }
          }
      else if(am_pmPart_st == " pm")
      {
          int castedTime;
          castedTime = stoi(concatenatedTime); //This is where we convert the string to int because its the only place it matters
          militaryTime = castedTime + 1200;
          cout &lt;&lt; "Corresponding military time is: " &lt;&lt; militaryTime &lt;&lt; " hours" &lt;&lt; endl;
      }
  
  }
  
  int main()
  {
      char DELEMETER = ':';
      char DELEMETER_sp = ' ';
      string time, firstPartofTime, secondPartofTime, am_pmPart_st, loweredAM_PM;
  
      cout &lt;&lt; "Enter the time in the format of: HH:MM AM/PM ";
      getline(cin, time);
      firstPartofTime = time.substr(0, time.find(DELEMETER));
      cout &lt;&lt; "The first digits of time " &lt;&lt; firstPartofTime &lt;&lt; endl;
      secondPartofTime = time.substr(time.find(DELEMETER) + 1, time.find(DELEMETER_sp)-1);
      cout &lt;&lt; "The second set of digits " &lt;&lt; secondPartofTime &lt;&lt; endl;
      am_pmPart_st = time.substr(time.find(DELEMETER_sp), time.size());
      cout &lt;&lt; "The am/pm part is:" &lt;&lt; am_pmPart_st &lt;&lt; endl;
  
      for(int i=0; am_pmPart_st[i]; i++) am_pmPart_st[i] = tolower(am_pmPart_st[i]); //Converts am/pm to lowercase
      cout &lt;&lt; am_pmPart_st &lt;&lt; endl;
  
      militaryConversion(am_pmPart_st, firstPartofTime, secondPartofTime);
  }
  </code></pre>