cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
Trouble reversing sentence
Trouble reversing sentence
Oct 21, 2013 at 12:52am UTC
billet07
(9)
I need to write a program that figures out if a sentence is a palindrome or not.
I was able to get the program to take a sentence and compress it to one word that is lower case, but do not know how to reverse the compressed word.
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main()
{
// Declarations: Declaring variables
string sentence, choice, reversed_word, lower_sentence;
int numletters, i;
char letter;
do
{
cout << "Enter a sentence to check: " << endl;
getline(cin, sentence);
numletters = sentence.length();
for (i=0; i<= numletters; i++)
{
letter = tolower(sentence[i]);
if (letter != ' ')
{
lower_sentence = lower_sentence + letter;
}
}
cout << "Compressed: " << lower_sentence << endl;
}
while (choice == "Y" || choice == "y");
system ("pause");
return 0;
}
Oct 21, 2013 at 1:50am UTC
LB
(13399)
Please do not post more than once:
http://www.cplusplus.com/forum/beginner/114217/
Topic archived. No new replies allowed.