I am trying to get positive integer numbers as inputs and checks to see if those numbers are palindromic. Like that;
Enter a positive integer (0 to exit): <1228>
1228 is not a palindrome
Enter a positive integer (0 to exit): <15851>
15851 is a palindrome
Enter a positive integer (0 to exit): <hello>
*** error: inputs must be an integer
Enter a positive integer (0 to exit): <919>
919 is a palindrome
Enter a positive integer (0 to exit): <-99>
*** error: inputs must be greater than zero
Enter a positive integer (0 to exit): <4115>
4115 is not a palindrome
Enter a positive integer (0 to exit): <0>
I tried something but couldn't finish all codes. I had trouble with filling the bool function.. How can I fill in that Function, and also does that code logical??
These are my codes..
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
#include <iostream>
using namespace std;
bool is_a_palindrome(char[]){
.
.
.
.
.
.
}
int main(int, char**){
const int x=80;
const int END_VALUE=0;
long int nbr;
char checkPal[x];
do{
cout<<"Enter a positive integer ("<<END_VALUE<<") to exit: ";
cin>>nbr;
char checkPal=nbr;
if (cin.fail()) {
cout << "*** error: inputs must be an integer" << endl;
continue; }
else if(nbr<0){
cout<<"*** error: inputs must be greater than zero"<<endl;
continue; }
else if(is_a_palindrome(char checkPal[x])){
cout<<nbr<<" is a Palindrome "<<endl;
}
else
cout<<nbr<<" is not a Palindrome"
}
while(nbr!=END_VALUE);
system("pause");
return EXIT_SUCCESS;
}
|
ALso there is one important note here
String objects cannot be used to determine if a number is a palindrome. In other words, this program must be implemented using an array of characters.