Apr 27, 2009 at 1:29pm UTC
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
Apr 27, 2009 at 1:38pm UTC
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.
Apr 27, 2009 at 1:40pm UTC
how to initialize num in the main .. can u help me
Apr 27, 2009 at 1:53pm UTC
can u teach me how to pass the value to the function as i was nt taught b4
Apr 27, 2009 at 2:11pm UTC
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;
}
Apr 27, 2009 at 2:16pm UTC
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.