I am creating a game where a player encounters different objects which increase/decrease the health.
I have an array with the obj name and effect which works perfectly
The problem occurs in this loop
while(gHealth >= 0 && gHealth <= 500)
{
srand(time(0));
int hitBy = (rand()%arrayL); // arrayL = number objects in array
cout << gName << " encountered " << objName [hitBy] << endl;
gHealth += objPower[hitBy];
cout << gName << "has a health of " << gHealth << endl;
}
Every time the player encounters same object. (what i mean is if the player encountered apple the first time then for the entire game he encounters apples)
How do i make random output each time it enters loop
Aucun commentaire:
Enregistrer un commentaire