ref: type casting
i want to write a program to enter a integer eg 1200, find its reverse and the subtract the orignal value from the reverse ie 1200-0012.
i try to enter the code and give me and error message. Can any one please help me to solve the problem:
int subtract(int year)
//find the reverse of the year, the difference between the original year &
//reverse year eg 1999-9991
{
int len;//string length
int i;
int diff;//absolute difference
int rYear;//reverse year
string sYear;//turn year into string
//change year into string and find its reverse order
sYear = year;
len = sYear.strlen();
i = sYear.strlen()-1;//set i = length of string-1
while (i>=0)
{
sYear.at(i);
i--;
}//end loop
//type cast
rYear = int(sYear);
//change string back into integer
diff = fabs(year - rYear);
return diff;
}//end diff