|
-
Oct 20th, 2001, 08:32 AM
#1
Thread Starter
Addicted Member
Random
Hello, how can I get a number between 1 and 6 in C++?
-
Oct 20th, 2001, 09:36 AM
#2
Frenzied Member
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;
}
-
Oct 20th, 2001, 09:37 AM
#3
Frenzied Member
Oh, this will generate 0 too. You may use if..else to check if it is 0 use rand again.
-
Oct 20th, 2001, 10:02 AM
#4
Hyperactive Member
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;
}
How about that?
-
Oct 20th, 2001, 12:28 PM
#5
-
Oct 20th, 2001, 03:45 PM
#6
Hyperactive Member
Originally posted by Vlatko
LOL
When you are in a hurry even that happens.
It happens to me all the time.
-
Oct 20th, 2001, 07:04 PM
#7
Thread Starter
Addicted Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|