Thread: C++ Help

  1. #1

    C++ Help

    I am writing the code to generate random number but I am not sure how to begin. Can someone please see if you can help me out.
    I am entering the function prototype and the function to generate a random number. The function will accept two integer arguments and return a random number between those two values (inclusive). For example, if the two argument values passed to the function are 1 and 10, the function will return a random integer number in the range of 1 to 10. From the main function, prompt the user for the two numbers, call the function, and display the random number.



  2. #2
    Registered User
    Join Date
    Apr 2002
    Well do you know how to generate a random number period? As in , do you know the standard call for a random number? That would be a good place to start. You just call rand( ) for a random number. Make sure you include stdlib.h ( or cstdlib ) for it though. You'll probably also want to seed the generator with something like the current time. Try time.h ( or ctime ) and then call srand( time( NULL ) ); Only call this once in the beginning of your program and you should be fine. If you have problems figuring out more, give this a try and post your code. We will be happy to help.

  3. #3
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Ontario, Canada
    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