Hello, how can I get a number between 1 and 6 in C++?
Printable View
Hello, how can I get a number between 1 and 6 in C++?
Code:#include <iostream.h>
#include <stdlib.h>
#include <time.h>
int main(int argc, char* argv[])
{
srand((unsigned)time( NULL ));
cout<<rand() % 7<<endl;
return 0;
}
Oh, this will generate 0 too. You may use if..else to check if it is 0 use rand again.
How about that?Quote:
Originally posted by Vlatko
Code:#include <iostream.h>
#include <stdlib.h>
#include <time.h>
int main(int argc, char* argv[])
{
srand((unsigned)time( NULL ));
cout<<(rand() % 6)+1<<endl;
return 0;
}
LOL :D
When you are in a hurry even that happens.
:D
It happens to me all the time.Quote:
Originally posted by Vlatko
LOL :D
When you are in a hurry even that happens.
:D
Thanks for the help