My program stuck in if statement, Help Please

I have two big problem in my code
one of them, I stuck in if statement and my program cannot continue running


bool Apothecary::BuyPotion(Potion& potion)// pop off stack
{

if (top)
{
potion = top->data;
Node *curr = top;
top = curr->next;
delete curr;
curr = NULL;
return true;

}
else
return false;

}

I is running fine until it reach to the last data in the list when top=NULL,and it won't return false

void BuyPotion(Apothecary& apo)
{
Potion potion;
PotionType potionCat;
if (apo.BuyPotion(potion)) {
potion.GetType(potionCat);
cout << "Congratulations! You just bought a " << PotionType(potionCat) << " potion!" << endl;
}
else {
cout << "There were no potions available." << endl;
}
}
Last edited on
Are you sure that top->next->next->next... eventually becomes null? Maybe you are forgetting to set it to null somewhere and so it has a random garbage value that is not null.
Last edited on
Topic archived. No new replies allowed.