cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
Random number
Random number
Jul 24, 2013 at 6:03pm UTC
closed account (
jwkNwA7f
)
Hello, I am making a guessing game where you have to guess a number. I can make a random number, but I want the number to stay the same each time you play. So it won't change each time someone plays, and so I can play too without knowing the answer.
Last edited on
Jul 24, 2013 at 6:34pm UTC
Jul 24, 2013 at 7:12pm UTC
Daleth
(1030)
Have you considered storing the generated value in a variable?
unsigned
int
correct_answer = rand();
And then you can have your game loop start after generating your value.
Jul 24, 2013 at 7:17pm UTC
closed account (
jwkNwA7f
)
Yes, I had, but I have been using
srand(time(NULL));
.
I guess that is why it was changing each time I used it.
Thank you for your help!
Topic archived. No new replies allowed.