Thread: Inserting commas using recursion

  1. #1

    Question Inserting commas using recursion

    I am working on a program for class where I need to insert commas into a number using a recursive function. The program needs to take into account negative numbers. What I have so far in regards to the function is:
    return n;
    return Number(n-(n%1000)):
    I need some direction as to how I submit a comma and if my program is flowing correctly. I tried to run it to try to get some idea as to what was going on but received "error LNK2001: unresolved external symbol_WinMain 16"

  2. #2
    Registered User blight2c's Avatar
    Join Date
    Mar 2002
    i don't understand what you mean by "insert commas into a number", a number string maybe. but the unresolved external usally means the function prototype doesn't match the defination header. if you post the code maybe i could help more

  3. #3
    This is the full code that I am using. Given a number eg. 10561. I am trying to right a recursive function that will display the number as 10,561.

    using namespace std;

    int Comma(int);//Recursive function to add commas to numbers

    int main()
    int number;//number to receive commas

    cout<<"Enter a number: ";

    return 0;
    int Comma(int n)
    return n;
    return Comma(n-(n%1000));

  4. #4
    Registered User
    Join Date
    Mar 2002
    experiment with your program.

    can you use % if n is negative?

    what happens if n is negative and you substract n % 1000?

    what happens if you put a line like:

    cout << ',';

    before as opposed to after this line:

    return Comma(n-(n%1000));


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Template Recursion Pickle
    By SevenThunders in forum C++ Programming
    Replies: 20
    Last Post: 02-05-2009, 09:45 PM
  2. Recursion... why?
    By swgh in forum C++ Programming
    Replies: 4
    Last Post: 06-09-2008, 09:37 AM
  3. Recursion
    By Lionmane in forum C Programming
    Replies: 11
    Last Post: 06-04-2005, 12:00 AM
  4. a simple recursion question
    By tetra in forum C++ Programming
    Replies: 6
    Last Post: 10-27-2002, 10:56 AM
  5. stack and recursion help needed!
    By LouB in forum C++ Programming
    Replies: 3
    Last Post: 07-01-2002, 02:19 PM