+ 2
[Solved] Need help with using srand() function
I cannot get this code to compile. I just saw the example given by the one of the lessons on functions, and seem to be having a strange error when compiling. https://code.sololearn.com/cvh30OCx3cDG/?ref=app
3 Answers
+ 7
change to
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main ()
{
srand(time(0));
int counter = 100;
while(--counter)
cout << 1 + (rand() % 6) << endl;
}
srand() should be used once
from there you use rand() to generate random numbers
+ 7
you welcome ;)
+ 2
Thank you!