hello there . I had a little problem with my code which I could solve I suppose to read something from user then tell him if palindrome or not the problem is that any word I enter is palidrome and when I repeat it I also got something wrong Do I have to use array instead?
Code:#include < iostream >
#include <string>
#include <algorithm>
using namespace std;
bool is_palindrome( string &s)
{
return equal ( s.begin(), s.end(), s.rbegin() );
}
int main ()
{
string input; char choice; int lc = 1;
do {
cout << "\nExecution number " << lc << ":" <<endl;
cout << "-------------------" << endl;
cout << "\nPlease enter a word or a phase :\n" << endl;
getline ( cin , input );
is_palindrome ( input );
if ( is_palindrome )
cout << "\n\"" << input << "\"" << " is palidrome.\n" << endl;
else
cout << "\n\"" << input << "\"" << " is not palidrome.\n" << endl;
do {
cout << "\nDo you want to do another computation ? Y/N \n" << endl;
cin >> choice;
}while ( choice != 'Y' && choice != 'y' && choice != 'n' && choice != 'N' && cout << "\nSorry wrong input!\n" );
++lc;
}while ( choice == 'y' || choice == 'Y' );
cout << "\n";
system ( "pause" );
return 0;
}
I tried cin.ignore ( 1000 , '\n' ) before the function call didnt work ;
this is the output I had
Execution number 1:
-------------------
Please enter a word or a phase :
elsa
"elsa" is palidrome.
Do you want to do another computation ? Y/N
y
Execution number 2:
-------------------
Please enter a word or a phase :
"" is palidrome.
Do you want to do another computation ? Y/N
thx for your help