### Random numbers not working

Ok, I decided to create a small program today to test out some new stuff I had learned, and for some reason, the random number generator always generates 18. I've tried moving srand(time(0)); to different places so It would only be called once, and it didn't work. Please take a look!
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136`` ``````#include #include #include #include using namespace std; int main() { int ans, random, evil, total; int male = 1; int female = 1; int vampire = 0; cout<<"Press 1 to start and 2 to exit"<> ans; if (ans == 1){ //main cout<<"Press 1 to begin the day and 2 to end"<> ans; if (ans == 1){ //start program bool start = true; srand(time(0)); while (start == true){ //day if (male >= 1 && female >= 1){ Sleep(2000); random == rand() %10 + 1; if (random >= 1 && random <= 20){ //spawn male male++; total = male + female; cout<= 80 && random <= 100){ //spawm female female++; total = male + female; cout<= 101 && random <= 105){ cout<<"VAMPIRE SHEEP"<= 21 && random <= 99){ cout<<"No sheep today"< 1){ if (random >= 1 && random <= 5){ cout<<"Evil sheep is dead"<= 6 && random <= 10){ cout<<"Evil sheep still alive"<

Thanks!

EDIT: srand is on line 28. I don't know why I put it there, I've been trying different places in the code.
Last edited on
Why are you using == for assigments .
Use a single = for all your assignments.
Whoops haha sorry. I'll fix that.
Topic archived. No new replies allowed.