Thread: On the wrong track for a Function Prototype

  1. #1

    On the wrong track for a Function Prototype

    I have started to work on this, but I am not sure if I am on the right track.

    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.

    So far I have done this:

    #include <iostream>
    #include <ctime>

    int main(void)
    int i;
    i = rand();
    std::cout <<" random number is " <<i <<std::endl;
    std::cout <<" generate random numbers from 0 to 10"


    If someone can please look and see where I need get this right.



  2. #2
    Registered User
    Join Date
    Feb 2002
    simply put, rand() returns some crazy number between 0 and something like the amount of time that has passed since the birth of unix...

    youre not going to get the number you want unless you modulus your rand()

    i = ( rand() % 10 ) + 1 // returns a random between 1 and 10
    I came up with a cool phrase to put down here, but i forgot it...

  3. #3
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Perhaps the f.a.q. button at the top of the page should be much larger and flashing red.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Be confused with one function prototype
    By chings in forum C Programming
    Replies: 3
    Last Post: 05-12-2009, 11:09 PM
  2. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  3. doubt in c parser coding
    By akshara.sinha in forum C Programming
    Replies: 4
    Last Post: 12-23-2007, 01:49 PM
  4. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  5. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM