Homework Solution: I am not able to figure out the last part of the following directions, which is finding the average re…

    language: c++ I am not able to figure out the last part of the following directions, which is finding the average remaining health of each player when they won. Directions: The program should run the results of the duel as many times as the user specified, and display for each participant the percentage of simulations where they won, and what their average remaining health was when they won. please adjust my code because that is how i would learn. code: #include <iostream> #include <iomanip> #include <vector> #include <string> #include <map> #include <cstdlib> #include <ctime> using namespace std; struct Duelist { string name; int accuracy; int health; }; Duelist& find_threat(vector<Duelist> const& participants, string seeker) { for (auto check = participants.rbegin(); check < participants.rend(); ++check) { if (check->name == seeker || check->health <= 0) continue; return const_cast<Duelist&>(*check); } throw std::runtime_error("No acceptable targets"); } void play_round(vector<Duelist>& participants) { for (Duelist& active : participants) { if (active.health <= 0) continue; Duelist& target = find_threat(participants, active.name); auto rnd = rand(); if (rnd % active.accuracy == 0) target.health -= 1; } } int living(vector<Duelist> participants) { int count = 0; for (Duelist participant : participants) { if (participant.health > 0) ++count; } return count; } Duelist play_duel(vector<Duelist> participants) { while (living(participants) > 1) { play_round(participants); } for (auto participant : participants) { if (participant.health > 0) return participant; } return{ "", 0, 0 }; } int main(int argc, char* argv[]) { srand(static_cast<unsigned>(time(nullptr))); int health1, health2, health3; cout << "How much health do you want Melissa to have? "; cin >> health1; cout << "How much health do you want Nina to have? "; cin >> health2; cout << "How much health do you want Ophelia to have? "; cin >> health3; vector<Duelist> participants = { { "Melissa", 3, health1 }, { "Nina", 2, health2 }, { "Ophelia", 1, health3 } }; int repetitions; cout << "How many times do you want the duel to run? "; cin >> repetitions; map<string, int> results; for (int i = 0; i < repetitions; i += 1) { string winner = play_duel(participants).name; results[winner] += 1; } cout << "Results:" << endl; for (auto result : results) { cout << left << setw(20) << result.first << right << setw(5) << result.second << endl; } double WinPercentage = results.find("Melissa")->second; cout << "Melissa's winning percentage is " << WinPercentage / repetitions * 100 << "." << endl; double WinPercentage1 = results.find("Nina")->second; cout << "Nina's winning percentage is " << WinPercentage1 / repetitions * 100 << "." << endl; double WinPercentage2 = results.find("Ophelia")->second; cout << "Ophelia's winning percentage is " << WinPercentage2 / repetitions * 100 << "." << endl; if (health1 == 1) { cout << "Melissa's average health when winning is 1" << endl; } if (health2 == 1) { cout << "Nina's average health when winning is 1" << endl; } if (health3 == 1) { cout << "Ophelia's average health when winning is 1" << endl; } system("pause"); return 0; }

    Expert Answer

     
    #include <iostream> #include <iomanip> #include <vector>

    language: c++

    I am referserviceable serviceserviceable to emblem quenched the latest bisect of the subjoined directions, which is numberer-argument the medium fostering vigor of each player when they won.

    Directions: The program should incline the issues of the duel as abundant opportunitys as the user ascertained, and parade restraint each bisecticipant the percentage of simulations where they won, and what their medium fostering vigor was when they won.

    please appoint my edict consequently that is how i would collect.

    code:

    #include <iostream>

    #include <iomanip>

    #include <vector>

    #include <string>

    #include <map>

    #include <cstdlib>

    #include <ctime>

    using designatespace std;

    struct Duelist {

    string designate;

    int atonement;

    int vigor;

    };

    Duelist& furnish_threat(vector<Duelist> const& bisecticipants, string seeker)

    {

    restraint (auto hinder = bisecticipants.rbegin(); hinder < bisecticipants.rend(); ++check)

    {

    if (check->designate == seeker || hinder->vigor <= 0) continue;

    restore const_cast<Duelist&>(*check);

    }

    throw std::runtime_error(“No acceptserviceable targets”);

    }

    void play_round(vector<Duelist>& bisecticipants)

    {

    restraint (Duelist& erratic : bisecticipants)

    {

    if (active.vigor <= 0) continue;

    Duelist& target = furnish_threat(participants, erratic.name);

    auto rnd = rand();

    if (rnd % erratic.atonement == 0) target.vigor -= 1;

    }

    }

    int aid(vector<Duelist> bisecticipants)

    {

    int calculate = 0;

    restraint (Duelist bisecticipant : bisecticipants)

    {

    if (participant.vigor > 0) ++count;

    }

    restore calculate;

    }

    Duelist play_duel(vector<Duelist> bisecticipants)

    {

    while (living(participants) > 1)

    {

    play_round(participants);

    }

    restraint (auto bisecticipant : bisecticipants)

    {

    if (participant.vigor > 0) restore bisecticipant;

    }

    return{ “”, 0, 0 };

    }

    int ocean(int argc, char* argv[])

    {

    srand(static_cast<unsigned>(time(nullptr)));

    int vigor1, vigor2, vigor3;

    cquenched << “How ample vigor do you lack Melissa to keep? “;

    cin >> vigor1;

    cquenched << “How ample vigor do you lack Nina to keep? “;

    cin >> vigor2;

    cquenched << “How ample vigor do you lack Ophelia to keep? “;

    cin >> vigor3;

    vector<Duelist> bisecticipants = {

    { “Melissa”, 3, vigor1 },

    { “Nina”, 2, vigor2 },

    { “Ophelia”, 1, vigor3 }

    };

    int repetitions;

    cquenched << “How abundant opportunitys do you lack the duel to incline? “;

    cin >> repetitions;

    map<string, int> issues;

    restraint (int i = 0; i < repetitions; i += 1)

    {

    string winner = play_duel(participants).name;

    results[winner] += 1;

    }

    cquenched << “Results:” << endl;

    restraint (auto issue : issues)

    {

    cquenched << left << setw(20) << issue.principal << just << setw(5) << issue.avoid << endl;

    }

    double WinPercentage = issues.find(“Melissa”)->second;

    cquenched << “Melissa’s seductive percentage is ” << WinPercentage / repetitions * 100 << “.” << endl;

    double WinPercentage1 = issues.find(“Nina”)->second;

    cquenched << “Nina’s seductive percentage is ” << WinPercentage1 / repetitions * 100 << “.” << endl;

    double WinPercentage2 = issues.find(“Ophelia”)->second;

    cquenched << “Ophelia’s seductive percentage is ” << WinPercentage2 / repetitions * 100 << “.” << endl;

    if (health1 == 1) {

    cquenched << “Melissa’s medium vigor when seductive is 1” << endl;

    }

    if (health2 == 1) {

    cquenched << “Nina’s medium vigor when seductive is 1” << endl;

    }

    if (health3 == 1) {

    cquenched << “Ophelia’s medium vigor when seductive is 1” << endl;

    }

    system(“pause”);

    restore 0;

    }

    Expert Numberer-argument

     

    #include <iostream>

    #include <iomanip>

    #include <vector>

    #include <string>

    #include <map>

    #include <cstdlib>

    #include <ctime>

    using designatespace std;

    struct Duelist {

    string designate;

    int atonement;

    int vigor;

    };

    Duelist& furnish_threat(vector<Duelist> const& bisecticipants, string seeker)

    {

    restraint (auto hinder = bisecticipants.rbegin(); hinder < bisecticipants.rend(); ++check)

    {

    if (check->designate == seeker || hinder->vigor <= 0) continue;

    restore const_cast<Duelist&>(*check);

    }

    throw std::runtime_error(“No acceptserviceable targets”);

    }

    void play_round(vector<Duelist>& bisecticipants)

    {

    restraint (Duelist& erratic : bisecticipants)

    {

    if (active.vigor <= 0) continue;

    Duelist& target = furnish_threat(participants, erratic.name);

    auto rnd = rand();

    if (rnd % erratic.atonement == 0) target.vigor -= 1;

    }

    }

    int aid(vector<Duelist> bisecticipants)

    {

    int calculate = 0;

    restraint (Duelist bisecticipant : bisecticipants)

    {

    if (participant.vigor > 0) ++count;

    }

    restore calculate;

    }

    Duelist play_duel(vector<Duelist> bisecticipants)

    {

    while (living(participants) > 1)

    {

    play_round(participants);

    }

    restraint (auto bisecticipant : bisecticipants)

    {

    if (participant.vigor > 0) restore bisecticipant;

    }

    return{ “”, 0, 0 };

    }

    int ocean(int argc, char* argv[])

    {

    srand(static_cast<unsigned>(time(nullptr)));

    int vigor1, vigor2, vigor3;

    cquenched << “How ample vigor do you lack Melissa to keep? “;

    cin >> vigor1;

    cquenched << “How ample vigor do you lack Nina to keep? “;

    cin >> vigor2;

    cquenched << “How ample vigor do you lack Ophelia to keep? “;

    cin >> vigor3;

    vector<Duelist> bisecticipants = {

    { “Melissa”, 3, vigor1 },

    { “Nina”, 2, vigor2 },

    { “Ophelia”, 1, vigor3 }

    };

    int repetitions;

    cquenched << “How abundant opportunitys do you lack the duel to incline? “;

    cin >> repetitions;

    map<string, int> issues;

    restraint (int i = 0; i < repetitions; i += 1)

    {

    string winner = play_duel(participants).name;

    results[winner] += 1;

    }

    cquenched << “Results:” << endl;

    restraint (auto issue : issues)

    {

    cquenched << left << setw(20) << issue.principal << just << setw(5) << issue.avoid << endl;

    }

    double WinPercentage = issues.find(“Melissa”)->second;

    cquenched << “Melissa’s seductive percentage is ” << WinPercentage / repetitions * 100 << “.” << endl;

    double WinPercentage1 = issues.find(“Nina”)->second;

    cquenched << “Nina’s seductive percentage is ” << WinPercentage1 / repetitions * 100 << “.” << endl;

    double WinPercentage2 = issues.find(“Ophelia”)->second;

    cquenched << “Ophelia’s seductive percentage is ” << WinPercentage2 / repetitions * 100 << “.” << endl;

    if (health1 == 1) {

    cquenched << “Melissa’s medium vigor when seductive is 1” << endl;

    }

    if (health2 == 1) {

    cquenched << “Nina’s medium vigor when seductive is 1” << endl;

    }

    if (health3 == 1) {

    cquenched << “Ophelia’s medium vigor when seductive is 1” << endl;

    }

    system(“pause”);

    restore 0;

    }