My assignment is to use arrays to construct a program that will determine if the input word is a palindrome or not. However, every input results in the program saying that it is a palindrome. I've tried many solutions but none seem to fix the issue.
//Display Program
#include<iostream>
using namespace std;
int palindrome(char letter[], int size)
{
int i;
int j= size - 1;
for(i = 0; i <= j; i++)
{
if (letter[i] != letter[j])
{
return 0;
}
else
j--;
}
return 1;
}
int main()
{
const int SIZE = 20;
char letter[SIZE];
char repeat;
int i;
int j;
int count = 0;
int size;
do
{
cout << "Enter a word (. to end the word): ";
for(i = 0; i < SIZE; i++)
{
cin >> letter[i];
if (letter[i] == '.')
{
break;
}
count++;
}
for(i = i - 1; i >= 0; i--)
{
cout << letter[i];
}
cout << "\n";
if (palindrome(letter, i))
{
cout << "This word " << "is a palindrome." << endl;
}
else
{
cout << "This word " << "is NOT a palindrome." << endl;
}