title: c++ palindrome program using arrays
body: <p>I'm having trouble with the first if statement, when the program enters the loop it skips over the if statement. My program is supposed to test if the input is a palindrome and then print it out, (the 'Reverse' array is just to print out the original phrase backwards if it passes through the test). If the palindrome is "madam I'm adam" the output should be "madamimadam" no capitalization or punctuation. I'm not sure if the arrays will take care of that or if I need another conditional test to take out those characters? If someone could please look over my code and tell me what's wrong/what I can do I'd greatly appreciate it.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  int main()
  {
  
      //Variables and Arrays
  
      char Phrase[80];
  
      char Reverse[80];
  
      char* Palindrome = Reverse;
  
      int i, j, test = 1;
  
      cout &lt;&lt; "Please enter a sentence to be reversed: ";
      cin &gt;&gt; Phrase;
  
      cin.getline(Phrase, 80);
      int length = strlen(Phrase);
  
      for(i = 0; i &lt; (length/2); i++) // do a loop from 0 to half the length of the string
      {
          if(test == 1) // test for palindrome
          {
              if(Phrase[i] != Phrase[length-i-1]) // check if the characters match
              {
                  test = 0; // if they don't set the indicator to false
              }
          }
          else
          {
              break; // if it is not a palindrome, exit the for loop
          }
      }
  
      if(test == 1) //test to print out the phrase if it's a palindrome
      {
          cout &lt;&lt; "Phrase/Word is a Palindrome." &lt;&lt; endl;
  
          for(j = strlen(Phrase) - 1; j &gt;= 0; Palindrome++, j--)
          {
              *Palindrome = Phrase[j];
              cout &lt;&lt; "The reverse is: " &lt;&lt; Reverse &lt;&lt; endl &lt;&lt; endl;
          }
      }
      else
      {
          cout &lt;&lt; "Phrase/Word is not a Palindrome." &lt;&lt; endl;
      }
  
      system("Pause");
      return 0;
  }
  </code></pre>