xStimpert xStimpert -4 years ago 143
C++ Question

SRAND() is not working in codeblocks?

#include <iostream>
#include <ctime>
using namespace std;


int main ()
{
srand(5);

int r = rand() % 100

cout << r << endl;
}


codeblocks throwing this error back saying i didn't declare srand or rand when i need them to just generate random numbers? I know it returns the same nmber everytime as i am learning cpp rn.

Answer Source

Put this at the top

#include <cstdlib>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download