Checking for Palindrome

I cannot figure out how to compress my sentence to one word in lower case. I was able to make the sentence lower case but do not know how to compress it to one word and then reverse it.
This is what I have so far:

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

int main()
{
// Declarations: Declaring variables
string sentence, choice, reversed_word, letter, lower_sentence;
int numletters, i;
char _1char;

do
{
cout << "Enter a sentence to check: " << endl;
getline(cin, sentence);

numletters = sentence.length();


for (i=0; i<= numletters; i++)
{
letter = tolower(sentence[i]);
lower_sentence = lower_sentence + letter;





}
cout << "Compressed: " << lower_sentence << endl;

for (

cout << "Do you want to try again? [Y|N] ";
cin>> choice;

}
while (choice == "Y" || choice == "y");

system ("pause");
return 0;
}
Try iterating over the lowercase sentence and adding each character which is not a space to a new string.
After cin>> choice; add this line:
 
        cin.ignore(1000, '\n'); // remove unwanted newline 

This is needed because the newline character '\n' will remain in the input buffer and the next getline will read everything up to that newline, resulting in an empty string.

The for loop repeats too many times:
 
    for (i=0; i<= numletters; i++)

it should be: i<numletters
Topic archived. No new replies allowed.