Thread: HELP! My rand() won't make a random number...

  1. #1
    Registered User
    Join Date
    Apr 2003

    Angry HELP! My rand() won't make a random number...

    Look at my code:

    #include <stdio.h>
    #include <stdlib.h>
    #include "D:\Dev-Cpp\klib.h"// My libary
    int main()
        int nums;
        nums = (rand() % 4);
        printf(" %d\n", &nums);
        end(); // My function
        return 0;
    and here what it prints:

    Where did it get that? Plz Help

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    >>printf(" %d\n", &nums);
    should be
    >>printf(" %d\n", nums);

    Also, read this if you want help on generating random numbers.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Ontario, Canada
    #include <time.h>
    // and add this to the start of main( )
    srand( time( NULL ) );
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 02-08-2009, 09:26 PM
  2. Random number array
    By matt_570 in forum C++ Programming
    Replies: 12
    Last Post: 11-13-2008, 04:44 PM
  3. xor linked list
    By adramalech in forum C Programming
    Replies: 23
    Last Post: 10-14-2008, 10:13 AM
  4. Counting number from a random file
    By kamisama in forum C Programming
    Replies: 42
    Last Post: 02-22-2005, 05:16 PM
  5. Replies: 25
    Last Post: 10-28-2001, 01:08 PM