My assignment: A palindrome is a string of characters that reads the same forwar
ID: 3650541 • Letter: M
Question
My assignment:A palindrome is a string of characters that reads the same forwards
as backwards. For example, the following are both palindromes:
1457887541
madam
Write a program that prompts the user to input a string of a size 50 characters or
less. Your program should then determine whether or not the entered string is a
palindrome. A message should be displayed to the user informing them whether
or not their string is a palindrome.
here is what I have:
**********************************************************************
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
char write[51];
char flip[51];
int length=0;
int count = 0;
int i=0;
cout << "Please enter a sentence with only 50 characters:" << endl;
cin >> write;
length = strlen(write);
for(count = length-1;count >= 0; count--)
{
flip[i] = write[count];
cout <<flip[i];
i++;
}
if(flip == write)
{
cout << "The input sentence or word is a palindrome." << endl;
}
else
{
cout << "The input sentence or word is NOT a palindrome." << endl;
}
return 0;
}
************************************************************************
I'm assuming that this won't work because the value of the character saved in the certain position in the array doesn't match the value of the character in the new saved array box. Please help.
P.S. This function runs, just that when I plug in "madam", it doesn't read it as a palindrome sentence.
Explanation / Answer
#include #include using namespace std; int main() { char write[51]; char flip[51]; int length=0; int count = 0; int i=0; cout = 0; count--) { flip[i] = write[count]; coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.