help with random number generator

This is a discussion on help with random number generator within the C Programming forums, part of the General Programming Boards category; I have an assignment for school, to make a long story short I'm having trouble with the random number generator. ...

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    22

    help with random number generator

    I have an assignment for school, to make a long story short I'm having trouble with the random number generator. I get two errors saying "error: expected expression before = token" they give the line number of the printf statment "printf("%d\n", rand() % (HIGH - LOW + 1) +LOW );". I dont understand what the problem is can anyone please help me.


    Code:
    	do
    	{
    			
    		/* gets time and convert seconds to unsigned int */
    		time_t now;
    	        time(&now);
    		srand(now);
    		
    		rand();
                    /*sets the bounds*/
    		printf("%d\n", rand() % (HIGH - LOW + 1) +LOW );
    		
    	/*	printf("%d", randnum); */
    		
    
    		++count;
    
    	} while (count <= 11);

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    My Hat of Guessing says that you did
    Code:
    #define HIGH = 10
    instead of the correct
    Code:
    #define HIGH 10
    (or whatever your number is).

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,261
    My thoughts exactly, except 2 minutes too late
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  4. #4
    Registered User
    Join Date
    Apr 2007
    Posts
    22
    ok, you'r both right, that did it. Thanks so much

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue w/ Guess My Number Program
    By mkylman in forum C++ Programming
    Replies: 5
    Last Post: 08-23-2007, 01:31 AM
  2. Good Random Number Generator
    By MethodMan in forum C Programming
    Replies: 4
    Last Post: 11-18-2004, 05:38 AM
  3. How do I restart a random number sequence.
    By jeffski in forum C Programming
    Replies: 6
    Last Post: 05-29-2003, 02:40 PM
  4. how to link random number generator with cpu?
    By chris285 in forum C++ Programming
    Replies: 5
    Last Post: 04-28-2003, 05:26 AM
  5. Seeding Random Number Generator
    By zdude in forum C++ Programming
    Replies: 2
    Last Post: 09-05-2002, 03:10 PM

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