Numbers of palindromes

Can you please tell me what i did wrong?
I have to enter some numbers and then to find out if they are palindromes or not,and if they are,how many of them are.

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
  #include <iostream>
using namespace std;

int main() {

    int num,n,c,rev=0,x;
    int i=1,s=0;

    cout << "Please enter the maximum of numbers you want to enter\nmax=";
    cin >> num;
    cout << "Now enter the numbers.\n";


    while (i<=num) {

    cout << "x= ";
    cin >> x;
        while (x>0){
        c=x%10;
        rev=rev*10+c;
        x=x/10;
    }
    n=x;
    if (rev==n) s++;
    i++;
    }

    cout << "The total of palindromes is " << s << endl;


    return 0;
}
On line 23 you have n = x but what is n? I suppose n was meant to have recorded the value of x before x entered the loops, so you need an additional statment b/w your current lines 17 and 18: n = x;
Last edited on
Thanks gunnerfunner! Now it works :D
Topic archived. No new replies allowed.