+ 1
Why other no then 0 is not working?
int main () { srand(time(0)); for (int x = 1; x <= 10; x++) { cout << 1 + (rand() % 6) << endl; } } If i put 1 or any no in o. It show error
3 Respuestas
+ 3
that has to do with the time function because it accepts no argument(NULL/0) or the address of a time_t object.
without arguments it returns the current number of seconds elapsed since 01/01/1970
you are using the current number of seconds elapsed to seed your pseudo random generation that would otherwise lead to repetitive output when you run your program multiple times.
Suggestion for future posts: when you post questions for help regarding erroneous behavior of your code, is a good practice to include also the error you get.
Proper questions lead to proper answers...
+ 2
what'sthe error?
0
Compiler error. Series of errors. Try it