Hunting Party [c++] help

Help(20 charactersssssss)

Code? Error? What you need help with?

1 Like

help idk for to create for soldeir in soldiers: in c++

int main() {
    // You can use findNearestEnemy() on your soldiers to get their nearest enemy instead of yours.
    while (true) {
        auto friends = hero.findFriends();
        // Use for-loop and for each friend:
        // help
            // If they see an enemy then command to attack.
            if (enemy) {
                hero.command(friend, "attack", enemy);
            }
            // Command to move east by small steps.
            
    }
    return 0;
}

@moonwatcher348 hello?

I’m not good at c++, but here is what I think should work

for (int i = 0; i < sizeof friends / sizeof friends[0]; i++) {
    auto friend = friends[i];
    // stuff
}

edit: oops, arr was supposed to be friends xD

1 Like

Have Error On The Code.

int main() {
    // You can use findNearestEnemy() on your soldiers to get their nearest enemy instead of yours.
    auto enemy = hero.findNearestEnemy();
    while (true) {
        auto friends = hero.findFriends();
        // Use for-loop and for each friend:
        for (int i = 0; i < sizeof friends / sizeof friends[0]; i++) {
            auto friends = friends[i];
            // If they see an enemy then command to attack.
            if (enemy) {
                hero.command(friend, "attack", enemy);
            }
            // Command to move east by small steps.
        }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
    }
    return 0;
}

while(true) makes an erorr line 4

It should be auto friend = friends[i];

4 Likes

Still Erorr

int main() {
    // You can use findNearestEnemy() on your soldiers to get their nearest enemy instead of yours.
    auto enemy = hero.findNearestEnemy();
    while (true) {
        auto friend = hero.findFriends();
        for (int i = 0; i < sizeof friends / sizeof friends[0]; i++) {
            auto friends = friends[i];
            // If they see an enemy then command to attack.
            if (enemy) {
                hero.command(friend, "attack", enemy);
            }
            // Command to move east by small steps.
        }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
    }
    return 0;
}


Well, it’s still error because you didn’t change your code. It should be auto friend, not auto friends.

1 Like

like this?
auto friend != hero.findFriends();

You changed the wrong part. Here you should leave friends, because it’s an array.

But here, it should be friend, because here you already find one friend.

1 Like

still
Erorr
auto friend = hero.findFriends[i];

int main() {
    // You can use findNearestEnemy() on your soldiers to get their nearest enemy instead of yours.
    auto enemy = hero.findNearestEnemy();
    while (true) {
        auto friend = hero.findFriends[i];
        for (int i = 0; i < sizeof friends / sizeof friends[0]; i++) {
            auto friends = friends[i];
            // If they see an enemy then command to attack.
            if (enemy) {
                hero.command(friend, "attack", enemy);
            }
            // Command to move east by small steps.
        }
    }
    return 0;
}


Check my previous message.

1 Like

like this?
auto friends = hero.findFriends[i];

Yes, and the next part, where is the friends[i]; , it should be auto friend.

Wait. It’s not [i]

1 Like

i mean its have been have a auto