My function won't compile :(. Any help?

This is a discussion on My function won't compile :(. Any help? within the C++ Programming forums, part of the General Programming Boards category; Hi all, I'm still kind of new to writing functions, and this is one i wrote that is supposed to ...

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    1

    My function won't compile :(. Any help?

    Hi all,
    I'm still kind of new to writing functions, and this is one i wrote that is supposed to generate a random numerical code of length "d", with maximum value for each digit of "h" and where "c" is the code.
    For example if d=4, h=3, then c could equal 1232, or 1132, or 2333 etc.

    Here's my function:

    int pickCode(int d, int c, int h);
    int pickCode(int d, int c, int h){
    using namespace std;
    int counter = 0;
    int digit;
    c = 0;
    while (counter<d) {
    rand( digit % d + 1);
    c = c*10 + digit;
    counter = counter + 1;
    }
    return c;
    }

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    Seems you are missing a particular detail of rand() that might be helpful.

    rand [C++ Reference]
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,558
    Seems like you missed this in your rush to post
    << !! Posting Code? Read this First !! >>
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Troubleshooting Input Function
    By SiliconHobo in forum C Programming
    Replies: 14
    Last Post: 12-05-2007, 06:18 AM
  2. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 01:53 AM
  3. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 12:03 PM
  4. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 09:18 AM
  5. Replies: 5
    Last Post: 02-08-2003, 06:42 PM

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