wads wrong with my programe

can some 1 help me solve this error and warning.. this is the programe


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

bool palindromes(long no);

int main ()
{
long num;

if (palindromes(num)==true)
{
cout<<num;
cout<<" is a palindrome.";
}

else
{

cout<<num;
cout<<" is not a palindrome.";
}

cout<<endl;
system("pause");
return 0;
}

bool palindromes(long no)
{
long num, quation, remainder,RN;

cout<<"Input a number to check if it is palindrome -> ";
cin>>num;

quation=num;
RN=0;
do
{
remainder=quation%10;
quation=quation/10;

RN=RN*10+remainder;
}

while (quation!=0);

if (num==RN)
{
return true;
}

else
{
return false;
}
}

i cant cout the correct number imputed
You have a problem with scope. The num in your palindromes function is not the same and the num in main, and you never initialize num in main.
how to initialize num in the main .. can u help me
Heres' a short bit on scope of variables: http://www.cplusplus.com/doc/tutorial/functions/

You could use pass by reference, so that your function modifies the same variable. You could also move
1
2
cout<<"Input a number to check if it is palindrome -> ";
cin>>num;

into main and then pass the value to the function.
can u teach me how to pass the value to the function as i was nt taught b4
Again, I will refer you to the Functions tutorial. http://www.cplusplus.com/doc/tutorial/functions/
It has explanations and examples of parameter usage, which is how data are passed to functions.
oic is this example right ???

#include <iostream>
using namespace std;

void duplicate (int& a, int& b, int& c)
{
a*=2;
b*=2;
c*=2;
}

int main ()
{
int x=1, y=3, z=7;
duplicate (x, y, z);
cout << "x=" << x << ", y=" << y << ", z=" << z;
return 0;
}
Yes, that is a good example of pass by reference. Using that technique, you should be able to rewrite your original program so that it does exactly what you want.
Topic archived. No new replies allowed.