# Digit Manipulation

• 02-24-2002
Unregistered
Digit Manipulation
I'm having so much trouble with this program its not even funny. I need to write a program to enable a user to enter a digit, and be able to reverse that digit(123 to 321), average the numbers of the digit, sum the numbers, and give the largest and smallest number. I'm majorly hitting a brick wall here. Here is the two functions I have so far for this program. Anyone with some advice would be greatly appreciated!

int GetNextDigit (int &iNumber)
//Function get last number from end

{
int iDigit;
iDigit = iNumber % 10;
iNumber /= 10;
return iDigit;
}

int ReverseDigits (int &iNumber)
{
int iDigit = 0;
do
{
GetNextDigit (&iNumber);
iDigit = iDigit * 10;
GetNextDigit (&iNumber);
iDigit += iDigit;
}
while (iNumber > 0);
return iDigit;
}

Something tells me I'm getting the logic wrong, but I'm lost as to where.
• 02-24-2002
taylorguitarman
:)
• 02-25-2002
swoopy
Try this:

int GetNextDigit (int &iNumber);
int ReverseDigits (int &iNumber);
int main(void)
{
int num = 1234;
cout << "num:" << num << endl;
cout << "num:" << ReverseDigits(num) << endl;
return 0;
}

int GetNextDigit (int &iNumber)
//Function get last number from end

{
int iDigit;
iDigit = iNumber % 10;
iNumber /= 10;
return iDigit;
}

int ReverseDigits (int &iNumber)
{
int iDigit = 0;
do
{
iDigit *= 10;
iDigit += GetNextDigit (iNumber);
}
while (iNumber > 0);
return iDigit;
}