Level 18 Muchkin Swarm Chest not opening

Hi there, I’m working in c++ on level 18 (munchkin swarm) and I keep getting the ‘ran out of time’ response but I’m not sure what to change or add to this code. I’m cleaving the munchkins but when I hit the chest, it doesn’t open at all. Please help!!

int main() {
    while(true) {
        // Check the distance to the nearest enemy.
        auto nearestEnemy = hero.findNearestEnemy();
        float distance = hero.distanceTo(nearestEnemy);
        // If it comes closer than 10 meters, cleave it!
        if (distance < 10) {
        // Else, attack the "Chest" by name.
        else {
    return 0;

hi, i have no knowledge of c++, but in my code, i attacked the chest only once in the else block, maybe that will do a difference?