[SOLVED] SteelClaw Gap(C++) Help

help here my code

// This level introduces the % operator, also known as the modulo operator.
// a % b returns the remainder of a divided by b
// This can be used to wrap around to the beginning of an array when an index might be greater than the length

// You start with 360 gold to build a mixture of soldiers and archers.
// this.built is an array of the troops you have built, ever.
// Here we use "this.built.length % summonTypes.length" to wrap around the summonTypes array
auto summonTroops() {
    auto type = summonTypes[hero.built.size() % summonTypes.size()];
    if(hero.gold >= hero.costOf(type)) {
        hero.summon(type);
    }
}

auto commandTroops() {
    auto friends = hero.findFriends();
    for(int friendIndex=0; friendIndex < friends.size(); friendIndex++) {
        auto friend = friends[friendIndex];
        // Use % to wrap around defendPoints based on friendIndex
        defendPoint == defendPoints & friendindex;
        // Command your minion to defend the defendPoint
        hero.command(friend, "defend", defendPoitns);
    }
}


auto defendPoints = {{35, 63},{61, 63},{32, 26},{64, 26}};

auto summonTypes = {"soldier","soldier","soldier","soldier","archer","archer","archer","archer"};


int main() {
    while(true) {
        summonTroops();
        commandTroops();
    }
    
    return 0;
}

updated code

// This level introduces the % operator, also known as the modulo operator.
// a % b returns the remainder of a divided by b
// This can be used to wrap around to the beginning of an array when an index might be greater than the length

// You start with 360 gold to build a mixture of soldiers and archers.
// this.built is an array of the troops you have built, ever.
// Here we use "this.built.length % summonTypes.length" to wrap around the summonTypes array
auto summonTroops() {
    auto type = summonTypes[hero.built.size() % summonTypes.size()];
    if(hero.gold >= hero.costOf(type)) {
        hero.summon(type);
    }
}

auto commandTroops() {
    auto friends = hero.findFriends();
    for(int friendIndex=0; friendIndex < friends.size(); friendIndex++) {
        auto friend = friends[friendIndex];
        // Use % to wrap around defendPoints based on friendIndex
        defendPoints % friendIndex;
        // Command your minion to defend the defendPoint
        hero.command(friend, "defend", defendpoints);
    }
}


auto defendPoints = {{35, 63},{61, 63},{32, 26},{64, 26}};

auto summonTypes = {"soldier","soldier","soldier","soldier","archer","archer","archer","archer"};


int main() {
    while(true) {
        summonTroops();
        commandTroops();
    }
    
    return 0;
}

updated code

// This level introduces the % operator, also known as the modulo operator.
// a % b returns the remainder of a divided by b
// This can be used to wrap around to the beginning of an array when an index might be greater than the length

// You start with 360 gold to build a mixture of soldiers and archers.
// this.built is an array of the troops you have built, ever.
// Here we use "this.built.length % summonTypes.length" to wrap around the summonTypes array
auto summonTroops() {
    auto type = summonTypes[hero.built.size() % summonTypes.size()];
    if(hero.gold >= hero.costOf(type)) {
        hero.summon(type);
    }
}

auto commandTroops() {
    auto friends = hero.findFriends();
    for(int friendIndex=0; friendIndex < friends.size(); friendIndex++) {
        auto friend = friends[friendIndex];
        // Use % to wrap around defendPoints based on friendIndex
        defendPoint = defendPoints[friendIndex % length.(defendPoints)];
        // Command your minion to defend the defendPoint
        hero.command(friend, "defend", defendPoints);
    }
}


auto defendPoints = {{35, 63},{61, 63},{32, 26},{64, 26}};

auto summonTypes = {"soldier","soldier","soldier","soldier","archer","archer","archer","archer"};


int main() {
    while(true) {
        summonTroops();
        commandTroops();
    }
    
    return 0;
}

line 20 ERORR

defendPoints is a array
ur legit commanding ur soldier to defend fort ticonderoga while going to costco or pizza, a soldier can’t be at 2 places at once

write defendPoint instead of defendPoints

1 Like

replace defendPoint to defendPoints

but its said
// Command your minion to defend the defendPoint

there no “s” there(20 chacracter)

Yeah just do this and it will work

do what(???++)

Do what you wrote here

what i did i wrote wherer

which one(20000000000000000000)

helooooooooooooooooooooooooooooooooooooooooo are u thereeeeeeeeeee

the erororo
i already put the “;” but still erorr

It should be defendPoints.length not length.defendPoints. You also need to add auto to define defendPoint.

auto defien
example?

1 Like

also change like this
“defendPoint = defendPoints[friendIndex % (defendPoints).length]”

Like here: auto friend = friends[friendIndex];

i copy the auto fried and put it up at defendPoint = defendPoints[friendIndex % (defendPoints).length]