C++ Help

This is a discussion on C++ Help within the C++ Programming forums, part of the General Programming Boards category; I am writing the code to generate random number but I am not sure how to begin. Can someone please ...

  1. #1
    Nazma
    Guest

    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.


    thanks

    Nazma

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    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
    Location
    Ontario, Canada
    Posts
    2,718
    FAQ
    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

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