The program compiles and runs just fine and gives the answers it is suppose to. (as far as I can tell). The problem, however, is that an input of very large numbers returns a false result of non palindromes although palindromes return true. Also, for functionality I would like to have added a loop to keep the user (me) from having to restart the program each time they wanted to test a number, but every time/place I would add it would give me an error and since it's more fluff that I want, not necessary, I took it out. I would like to put it back in though if someone could give me a good hint as to where to place it.
I'm sure experts have probably seen this program many times from us beginners. :
#include <cstdlib>
#include <iostream>
#include <cmath>
usingnamespace std;
bool isNumPalindrome (int num); /* function prototype */
int main()
{
bool isNum = false;
int integer = 0;
cout << "Which number do you want to see whether it is a palindrome?"
<< endl;
cin >> integer;
isNum = isNumPalindrome (integer);
if (isNum == true)
cout << "Your number is a palindrome"; /*next two statement display results */
else
cout << "Your number is not a palindrome";
cout << endl;
system("pause"); /* used for editor/compiler purposes to see output */
}
bool isNumPalindrome(int num) /* function that determines if palindrome:*/
//This function was prewritten from the text is not program authors property
{
double pwr = 0.0;
if(num < 5)
returntrue;
else
{
while (num / static_cast<double>(pow(10.0, pwr)) >= 10)
pwr++;
while (num >= 10)
{
int tenTopwr = static_cast<int>(pow(10.0, pwr));
if ((num / tenTopwr) != (num % 10))
returnfalse;
else
{
num = num % tenTopwr;
num = num / 10;
pwr = pwr - 2;
}
}
returntrue;
}
}