srand() and If-statements | SoloLearn: Learn to code for FREE!

+3

srand() and If-statements

How do I generate a number when I have multiple If-statements? Where should I place the srand() function, before or after conditions? And what else do I need to add to the code

11/27/2016 12:21:35 PM

Julia Melnik

2 Answers

New Answer

+4

To generated random number you need to use rand() function and srand() function use to initialization of rand. Put your srand above if statement. And initialize rand by srand(time(NULL)). You have to use ctime header file for time function. it would work perfect. if you want it within a range use rand()%(max-min+1)+min

0