+ 1

Why in C++ randomize() go out of scope when I decleared it in main() and included the header file stdlib. h????

randomize function out of scope

18th Sep 2017, 7:49 PM
Captain Aniket
Captain Aniket - avatar
3 Réponses
+ 7
randomize() random() is a pre standardized C++ way of doing things and is usually only available in Turbo C++ and Dev C++ compilers which are very old. This form of getting random numbers won't work in the playground as it uses standardized C++ that conforms to the ANSI C++ Standard. You need to use rand() and srand() instead. #include <iostream> #include <stdlib.h> #include <time.h> using namespace std; int main() { srand(time(0)); int x=5; x = rand() % x + x; cout << x; return 0; }
18th Sep 2017, 9:01 PM
ChaoticDawg
ChaoticDawg - avatar
+ 3
Provide the code so we can see what the problem might be.
18th Sep 2017, 8:11 PM
ChaoticDawg
ChaoticDawg - avatar
18th Sep 2017, 8:20 PM
Captain Aniket
Captain Aniket - avatar