Determine if the word given by the user is a palindrome or not, by making the word backwards and comparing it to the original word with a simple “if condition”.
//CODE:
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
string word, fin;
string is_palindrome(string word)
{
string backwards;
cout << “Type a word: n”;
cin >> word;
int large = word.length();
for (int x = large – 1; x >= 0; x–)
{
backwards += word[x];
}
if (backwards == word)
{
fin = “Your word IS a palindrome”;
}
else
fin = “Your word IS NOT a palindrome”;
return fin;
}
int main()
{
cout << is_palindrome(fin);
}
Quiz 5 by everolivares is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.