#include <iostream>
#include <cmath>
#include <iomanip>
#include <string>
usingnamespace std;
//-------------------------------------------------------------------------------------------------
void input(string&s);
int isPalindrome(const string &s);
void print(string s, string A[], int z);
//-------------------------------------------------------------------------------------------------
int main(){
char repeat;
do
{
int count=0;
string x,A[count];
int store;
input(x);
store=isPalindrome(x);
print(x,A,store);
cout << endl << "Do you wish to continue? Enter w or y.";
cin >> repeat;
}while(repeat == 'w' || repeat == 'y');
return 0;
}
//-------------------------------------------------------------------------------------------------
void input(string&s)
{
cout << "Enter a word and this will check if it is a palimdrome or not: ";
cin >> s;
}
int isPalindrome(const string &s)
{
int x,mid;
x = s.size() - 1; // marks end of string s
mid = s.size() / 2 + 1; // marks middle of string s
for(int count = 0; count != mid; ++count, --x)
{
if (s[count] != s[x]) { return -1; } // palindrome
}
return 0; // not palindrome
}
void print(string s, string A[], int z)
{
int count;
if (z == -1)
cout << "The string " << s << " is a palindrome." << endl;
else
cout << "The string " << s << " is not a palindrome." << endl; //we want to the program to look at the first element and the last element at the same time, how do i do that?
cout << "The character in position " << A[count] <<" is " << s.size() << endl;
cout << "The character in position " << A[s.size()-1] << " is " << A[s.size()] << endl;// what goes in here? do i need to declare another variable to get the 2 mismatched position
}
Enter a word and this will check if it is a palindrome or not: pip
The string pip is a palindrome.
Do you want to continue (y or n): y
Enter a word and this will check if it is a palindrome or not: pie
The string pie is not a palindrome.
The first character is p.
The last character is e.
Do you want to continue (y or n): g
y or n: 3
y or n: wywst
y or n: n