440,666 Members | 1,909 Online
Need help? Post your question and get tips & solutions from a community of 440,666 IT Pros & Developers. It's quick & easy.

# Generate a random number then use that to divide the user input number

 P: 64 Like the titles says I'm suppose to generate a random number then divide that by a number inputed by a user. The random number can range from 2-8. I tried to do the code, but I get some weird result here is the result Expand|Select|Wrap|Line Numbers Please enter a number:  18 a. number                         18.00 b. the random number              6    00-1.#J << suppose to be 3 , but I get this number. (Trying to get 18 divided by 6.   This is the code I have so far. Expand|Select|Wrap|Line Numbers int main (void)   { //    Local Declarations      double number;     float result;     float random = 2 + rand()%8;   //    Statements      printf("Please enter a number:");     scanf("%lf", &number);     srand(time(NULL));           printf("a. number\t\t\t %5.2lf\n", number);     printf("b. the random number\t\t  %d\n", rand() % (int)random + 2);     result = number / random;     printf(" the result is %5.2lf", result);     Thanks in advance! Jan 31 '07 #1