Hello Everyone,
I am in need in help with a palindrome program. Below is what I have, but keeps crashing and I am not sure why. Yes, I am a newbie to programming and C++.
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
usingnamespace std;
//Starting point. This program will ask the user to input a word, and the program will reply if it is a palindrome until END is typed to terminate.
int main()
{
string word972;
bool end;
//Asking user to input a word.
do{
cout << "Please enter a word to find out if it is a palindrome or type END to terminate." << endl;
cout << endl;
cin>> word972;
//Break function for "END".
while (word972.length())
(word972 != "END");
if (!"END") { break; }
if (word972 [0] == 'E' && word972 [1] =='N' && word972 [2] == 'D' && word972 [3] == '\0')
end = true;
else
end = false;
int length = (word972.length());
// Bool and for loop for word input, also to display word as it is typed.
bool palindrome=true;
for (int i=0; i<length; i++)
{
if(toupper(word972[i])!=toupper(word972[length-i-1]))
if(word972[i]!=word972[length-1-i])
palindrome=false;
}
// Output of palindrome respone.
if (palindrome)
{
cout << word972 << " is a palindrome" << endl;
}
else
{
cout << word972 << " is not a palindrome" << endl;
}
// Whlie loop until END is typed to terminate.
}
while (word972!="END");
{
cout << endl << "This is the end"<<endl;
}
system ("PAUSE");
return(0);
}
#include <iostream>
usingnamespace std;
int main()
{
char word[10];
for ( int x = 0; x < 10; x++ ) { word[x] = ' '; } //initialize array to nothing
cin >> word;
char palindrome[10];
for ( int x = 0; x < 10; x++ ) { palindrome[x] = word[x]; } // copy to palindrome
int count = 9;
for ( int x = 0; x < 10; x ++ ) { if ( word[x] != palindrome[count] ) { cout << "Not a palindrome";}
else { count --; }
}
if ( count == 0 ) {cout << "Is a palindrome";}
return 0;
}
This is a VERY SHITTY example to get you thinking about the logic.