Not exactly sure what you mean, because it looks like you already are, for at least color and friendly (once you move srand out of the constructor and into main). But you are still assigning age = 0; and happiness = 20; each time. If you want those to be random as well, assign them as a random number, like age = rand() % 10 + 1; or something.
You also could just have one comparison instead of four:
1 2
int random2 = rand() % 4 + 1; // generates either 1, 2, 3, 4
friendly = (random2 == 3); // assigns true to friendly if random2 == 3, false otherwise.
Also, you have some errors in boolean logic.
amount > 1 || amount <5
I believe you mean to do amount > 1 && amount < 5.
amount > 1 || amount < 5 will always evaluate to true, since it's the union of everything about 1 and everything below 5. Try it with some example values like amount = 0.
thanks Ganado very good point it should be && nice spot =)
the code now seems to run perfect after moving srand() to main just wondering how come you can only call srand() once and when I called it from inside the constructor how come it gave me the same results for each object?
Hi Ganado I found the answer I'll post it here in case anyone else stumbles upon this thread
anyway Srand () takes a seed,Rand uses this seed to produces a set of random values based on the seed now in my program the seed was always the same because the code was being executed in the same second which will give the same seed so the sequence of random values will always be the same
as Ganado said to avoid this just set the seed once in the application,and you should be fine but note that for short applications such as command line applications like mine if you were to by chance run two instances of the program in the same second the seed would be the same so it would product the same sequence of values