Palindrome

Whats wrong with my programme? the cmd does not show what it suppose to show.(My programme is to generate out palindrom from 11 to 88 . reverse and add the original number those which are not palindrome for a maximum of 6 time untill they become a palindrome)

Here is my main code....

# include <iostream>
# include <cstdlib>
using namespace std ;

int palindrome(int number) ;
bool check(int number) ;

int main (void)
{
int iteration , count ,temp ;
count = 0 ;
for (iteration = 1 ; iteration <= 6 ; iteration ++)
{
cout <<iteration
<<" iteration"
<< endl ;
for (int number = 10 ; number <=88 ; number ++)
if(!check(number))
do
{
temp = number ;
palindrome(number) ;
number = number + temp ;
if(!check(number))
count++ ;
}
while (count <=6) ;
if(count == iteration)
cout <<"number " ;
}
system("pause") ;
return 0 ;
}

bool check(int number)
{
int reverseno , N ;
reverseno = 0 ;
N = number ;

while (number != 0)
{
reverseno = reverseno * 10 + N%10 ;
N = N/10 ;
}
if (number == reverseno)
return true ;
else
return false ;
}
int palindrom(int number)
{
int reverseno , N ;
reverseno = 0 ;
N = number ;

while (number != 0)
{
reverseno = reverseno * 10 + N%10 ;
N = N/10 ;
}
return reverseno ;
}








Last edited on
Typo. You defined the function palindrom.

I think the reason you're getting a link error is that you have a palindrome function prototype (in your header), so the compiler knows that the function exists. Because of the typo, though, it can't find the function definition.

EDIT:

I really wish you wouldn't edit the original post to correct the error that you originally asked about. Not only does it do a disservice to others that may have the same problem, it makes me look silly for answering a seemingly unrelated question.
Last edited on
In response to your new question, you are doing a couple of suspicious things in your code. First, the palindrome
function returns an int, but you treat it as if it has a void return type (i.e. you do not make use of the return
value). Second, take a look at this for loop:
1
2
3
4
5
6
7
8
9
10
11
for (int number = 10 ; number <=88 ; number ++)
if(!check(number))
do
{
temp = number ;
palindrome(number) ;
number = number + temp ;
if(!check(number))
count++ ;
}
while (count <=6) ;

You increment number as you loop, but you also change it inside the loop. I
didn't look to see what is actually happening to the value of it, but I'm about 100% sure it's not what you expect.

Third, you create an infinite loop:
1
2
3
4
5
while (number != 0)
{
reverseno = reverseno * 10 + N%10 ;
N = N/10 ;
}
Last edited on
Okay sorry about that... I will change it back. As for the programme, i am still working on it. But thanks anyway.
Last edited on
Topic archived. No new replies allowed.