dimanche 11 janvier 2015

C++ Random Number Generator [duplicate]


This question already has an answer here:




I am trying to create a basic program in C++ that returns a random number each time the program is run. Very basic. But every time I run the program, I get the result



The random number selected was 41.


I have recompiled various times, but it makes no difference. My code is as follows:



#include <cstdlib>
#include <iostream>

using namespace std;

int main()
{
float num = rand();
cout<<"The random number selected was "<<num<<"\n";
cin.get();

return 0;
}


I use Dev-C++ as an IDE, but do not know my compiler, as when building the app, it simply says 'Default compiler'.


All answers (that are relevant) gladly appreciated!





Aucun commentaire:

Enregistrer un commentaire