Results 1 to 3 of 3

Thread: c c++

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2000
    Location
    Mirfield,West Yorkshire,Englan
    Posts
    11
    I am studying for a vb degree and I am at present learning 'c'.
    I have a question to answer which is to build a pgm that prints out the number of people in a bus queue using the rand function there must never be no people in the queue
    and a person departs or arrives every 30 seconds It is the rand function that is a problem to me, where do I put rand within the c program.

    Hope someone can help

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    rand() returns a random double between 0 and 1, so try something like:
    Code:
    long ulNumPeople = (long)((rand() * 50) + 1);
    ...which gives a maximum of 51 people, and a minimum of 1.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    Which is the random function that returns an integer then? I'm sure I've seen code that's something like (rand % 50) + 1
    Harry.

    "From one thing, know ten thousand things."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width