# 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; }

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

language: c++

I am refercogent cogent to illustration quenched the conclusive divorce of the aftercited directions, which is sentence the medium cherishing soundness of each player when they acquired.

Directions: The program should work the fruits of the duel as frequent durations as the user specific, and evince coercion each divorceicipant the percentage of simulations where they acquired, and what their medium cherishing soundness was when they acquired.

please command my enactment owing that is how i would gather.

code:

#include <iostream>

#include <iomanip>

#include <vector>

#include <string>

#include <map>

#include <cstdlib>

#include <ctime>

using spectryspace std;

struct Duelist {

string spectry;

int ratification;

int soundness;

};

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

{

coercion (auto obstruct = divorceicipants.rbegin(); obstruct < divorceicipants.rend(); ++check)

{

if (check->spectry == seeker || obstruct->soundness <= 0) continue;

revert const_cast<Duelist&>(*check);

}

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

}

void play_round(vector<Duelist>& divorceicipants)

{

coercion (Duelist& locomotive : divorceicipants)

{

if (active.soundness <= 0) continue;

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

auto rnd = rand();

if (rnd % locomotive.ratification == 0) target.soundness -= 1;

}

}

int assistance(vector<Duelist> divorceicipants)

{

int sum = 0;

coercion (Duelist divorceicipant : divorceicipants)

{

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

}

revert sum;

}

Duelist play_duel(vector<Duelist> divorceicipants)

{

while (living(participants) > 1)

{

play_round(participants);

}

coercion (auto divorceicipant : divorceicipants)

{

if (participant.soundness > 0) revert divorceicipant;

}

return{ “”, 0, 0 };

}

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

{

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

int soundness1, soundness2, soundness3;

cquenched << “How considerable soundness do you omission Melissa to possess? “;

cin >> soundness1;

cquenched << “How considerable soundness do you omission Nina to possess? “;

cin >> soundness2;

cquenched << “How considerable soundness do you omission Ophelia to possess? “;

cin >> soundness3;

vector<Duelist> divorceicipants = {

{ “Melissa”, 3, soundness1 },

{ “Nina”, 2, soundness2 },

{ “Ophelia”, 1, soundness3 }

};

int repetitions;

cquenched << “How frequent durations do you omission the duel to work? “;

cin >> repetitions;

map<string, int> fruits;

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

{

string winner = play_duel(participants).name;

results[winner] += 1;

}

cquenched << “Results:” << endl;

coercion (auto fruit : fruits)

{

cquenched << left << setw(20) << fruit.chief << proper << setw(5) << fruit.succor << endl;

}

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

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

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

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

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

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

if (health1 == 1) {

cquenched << “Melissa’s medium soundness when engaging is 1” << endl;

}

if (health2 == 1) {

cquenched << “Nina’s medium soundness when engaging is 1” << endl;

}

if (health3 == 1) {

cquenched << “Ophelia’s medium soundness when engaging is 1” << endl;

}

system(“pause”);

revert 0;

}

## Expert Tally

#include <iostream>

#include <iomanip>

#include <vector>

#include <string>

#include <map>

#include <cstdlib>

#include <ctime>

using spectryspace std;

struct Duelist {

string spectry;

int ratification;

int soundness;

};

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

{

coercion (auto obstruct = divorceicipants.rbegin(); obstruct < divorceicipants.rend(); ++check)

{

if (check->spectry == seeker || obstruct->soundness <= 0) continue;

revert const_cast<Duelist&>(*check);

}

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

}

void play_round(vector<Duelist>& divorceicipants)

{

coercion (Duelist& locomotive : divorceicipants)

{

if (active.soundness <= 0) continue;

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

auto rnd = rand();

if (rnd % locomotive.ratification == 0) target.soundness -= 1;

}

}

int assistance(vector<Duelist> divorceicipants)

{

int sum = 0;

coercion (Duelist divorceicipant : divorceicipants)

{

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

}

revert sum;

}

Duelist play_duel(vector<Duelist> divorceicipants)

{

while (living(participants) > 1)

{

play_round(participants);

}

coercion (auto divorceicipant : divorceicipants)

{

if (participant.soundness > 0) revert divorceicipant;

}

return{ “”, 0, 0 };

}

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

{

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

int soundness1, soundness2, soundness3;

cquenched << “How considerable soundness do you omission Melissa to possess? “;

cin >> soundness1;

cquenched << “How considerable soundness do you omission Nina to possess? “;

cin >> soundness2;

cquenched << “How considerable soundness do you omission Ophelia to possess? “;

cin >> soundness3;

vector<Duelist> divorceicipants = {

{ “Melissa”, 3, soundness1 },

{ “Nina”, 2, soundness2 },

{ “Ophelia”, 1, soundness3 }

};

int repetitions;

cquenched << “How frequent durations do you omission the duel to work? “;

cin >> repetitions;

map<string, int> fruits;

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

{

string winner = play_duel(participants).name;

results[winner] += 1;

}

cquenched << “Results:” << endl;

coercion (auto fruit : fruits)

{

cquenched << left << setw(20) << fruit.chief << proper << setw(5) << fruit.succor << endl;

}

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

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

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

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

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

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

if (health1 == 1) {

cquenched << “Melissa’s medium soundness when engaging is 1” << endl;

}

if (health2 == 1) {

cquenched << “Nina’s medium soundness when engaging is 1” << endl;

}

if (health3 == 1) {

cquenched << “Ophelia’s medium soundness when engaging is 1” << endl;

}

system(“pause”);

revert 0;

}