Problem with Palindromes

I'm writing a program using functions that takes an integer and determines whether or not it is prime and whether or not it is a palindrome. At the moment, I'm getting these errors:
1
2
3
4
lab9_functions.cpp: In function ‘int reverse(int*)’:
lab9_functions.cpp:45: error: invalid operands of types ‘int [10]’ and ‘int’ to binary ‘operator%’
lab9_functions.cpp:49: error: invalid operands of types ‘int [10]’ and ‘int’ to binary ‘operator/’
lab9_functions.cpp:50: error: invalid operands of types ‘int [10]’ and ‘int’ to binary ‘operator%’


If I make my variables arrays, the function that reversed the digits doesn't like it. But if they're not arrays, the function that compares them to determine whether or not they're palindromes doesn't like it.

Here's my code:
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
int number [10];
int integer [10];
bool isPrime (int number)
{
    bool isPrime=false;
    for (int divisor = 2; divisor <= number/2; divisor++) 
    {
        if ( number%divisor != 0)
        {
            isPrime=true;
        }
    }
}
bool isPalindromicPrime (bool isPrime, int reverse)
{
    if (isPrime=true) 
    {
        int j;
        for (j=0; j<=10; j++) 
        {
            if (integer [j] != number [j]) 
            {
                isPrime=false;
            }
        }
        return true;
    }
    else
    {
        return false;
    }
}
int reverse (int integer [])
{
    int count, i=0;
    int A=10;
    for (count=10; A>9; count*=10) 
    {
        A=number%count;
    }
    while (count>0) 
    {
        integer[i]=number/count;
        number=number%count;
        count/=10;
        i++;
    }
    while (i>=0) 
    {
        cout << integer [i];
        i--;
    }
}



Thank you!
Last edited on
Well you have to make up your mind. Either you're using an array or you're not.

It looks like you wrote half of this code as if you were using an array and the other half as if you weren't. So of course they're not going to work together.

On solution is to use both. Keep the number as a single integer in one variable, then split it into an array of digits in another variable.
Topic archived. No new replies allowed.