I'm trying to create a program that allows the user to input a word (I am using cin.getline to put the input into a char array), and then calls a function to determine if the word is a palindrome. If it is, I cout << "It's a palindrome." and if not, I cout the opposite. My problem is that my code will not compile and I can't figure out why. Here is the code:
#include<iostream>
#include<string>
#include<cstring>
usingnamespace std;
int pcheck(char word[], char rword[], constint SLEN);
int main(){
char w[100];
int p;
cout << "Which word would you like to check to see if it's a palindrome?" << endl;
cin.getline(w, 99);
constint SLEN=strlen(word);
char rword[SLEN];
for(int i=0, i<SLEN, i++){
rword[i]=word[SLEN-i];
}
int p=pcheck(word, rword, SLEN);
if(p==SLEN){
cout << "It is a palindrome!" << endl;
}
else{
cout << "It is not a palindrome." << endl;
}
}
int pcheck(char word, char rword, constint SLEN){
int j=0, partn=0;
while(j<SLEN){
if(word[j]==rword[j]{
partn++;
}
else{
cout << "Not a palindrome" << endl;
}
j++
}
In case you can't understand my logic, I am trying to get the word, reverse it, and then compare each letter in the two arrays. If they are the same letter, I increase a counter which is returned to main. If the returned number is the same as the length of the array, it is a palindrome. I just can't figure out what is wrong with my program causing it to be unable to compile.