Digit Manipulation

This is a discussion on Digit Manipulation within the C++ Programming forums, part of the General Programming Boards category; I'm having so much trouble with this program its not even funny. I need to write a program to enable ...

  1. #1
    Unregistered
    Guest

    Unhappy 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.

  2. #2
    Fingerstyle Guitarist taylorguitarman's Avatar
    Join Date
    Aug 2001
    Posts
    564
    Attached Files Attached Files
    If a tree falls in the forest, and no one is around to see it, do the other trees make fun of it?

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    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;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. error msg instead of the result so far
    By maybabier in forum C Programming
    Replies: 25
    Last Post: 03-20-2009, 02:45 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 12:41 PM
  3. Adding a Large number digit by digit
    By mejv3 in forum C Programming
    Replies: 1
    Last Post: 09-14-2007, 03:28 AM
  4. newbie programmer - needs help bad.
    By hortonheat in forum C Programming
    Replies: 17
    Last Post: 10-20-2004, 05:31 PM
  5. Roman number converter
    By BalanusBob in forum C++ Programming
    Replies: 8
    Last Post: 04-23-2002, 06:29 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21