Palindrome

I need to create a program and have it output if it is a palindrome or not.
I have to use two function, one that collects the input and the other determines if the string is a palindrome or not.

The output should look like
"The string mom is a palindrome" or "The string momx is not a palindrome. The character in position 0 is m, while the character in position 3 is x"

This is what I have so far

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>
#include <string>
using namespace std;
#define s string
int userinput (int& x, string s);
int checkinput (int& n, string s);
int main ()
{
int x,n;
char flag = 'y';
while (flag == 'y' || flag == 'Y')
{
userinput(x,s);
checkinput(n,s);
cout << Continue? Type y for yes, anything else for no" << endl;
cin >> flag;
}
return 0;
}
int userinput (int& x, string s)
{
cout << "String: ";
cin >> x;
return x;
}
int checkinput (int& n, string s)
{
for (int j = 0; j<= s.length; j++)
{

}
return n;
} 
Last edited on
You have a problem in your "checkinput()" function. Your for-loop limit should be: j < s.length;

To see if what the user types is a palindrome, you're going to need to first compare the beginning letter to the last letter, then the next letter to the next-to-the-last letter, and so on.
Topic archived. No new replies allowed.