Little adivce please with my unbroken/broken assignment please.

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. :

Thanks Much.
M

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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <cstdlib>
#include <iostream>
#include <cmath>
     
using namespace 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)
            return true;
        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))
                    return false;
                else
                {
                    num = num % tenTopwr;
                    num = num / 10;
                    pwr = pwr - 2;
                 
                }
            }
                return true;
        }
    }
Sorry, I should have and thought I did post this in the beginner section. Feel free to respond though if you would like. :)
If you treat the input as a string, rather than a number, then you won't have a length limit and your program will work with words too.

You could add a loop within main that queries if you want to continue:
1
2
3
4
5
6
7
8
main:
    declare variables
    do
        prompt for palindrome input
        process palindrome entry

        ask user if we should quit
    while (quit is no)
Last edited on
Topic archived. No new replies allowed.