Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Part 2 Now that you are done your battle() function, you will write code in your

ID: 3566749 • Letter: P

Question

Part 2 Now that you are done your battle() function, you will write code in your main() function to use it to answer a bunch of what -if type questions, such as 'Which weapon is best against whit h monster? and Can the hero expect to survive a battle against any of the monsters?' We'll answer the questions using a technique called simulation: we'll set up the battle once, then play the battle 1000 times, collecting data each time. Then we'll use simple summaries to draw conclusions. We'll need two steps. Part 2 Step 1: Your program will allow the user to customize the basic attributes for the Hero and the Monster. Your program should do this as follows: 1. First, set the Hero's base Health to 50. 2. Second. ask the user (using cin) for the Hero's weapon: The user should type in one of sword, axe or dagger. ? A sword gives the hero 8 Strength and 70 Accuracy. ? An axe gives the hero 10 Strength and 50 Accuracy. ? A dagger gives the hero 4 Strength and 95 Accuracy.

Explanation / Answer

Below I've provided the answer for PART 1 & Part 2 step 1....for the last I think you should do it on your own. I hope you'll rate me BEST ANSWER :)

/* PART - 1 */

int battle(int HeroHealth, int HeroStrength, int HeroAccuracy, int MonsterHealth, int MonsterStrength, int MonsterAccuracy){
   int attack, turn = 1;
   do{
       attack = rand() % 100 + 1;
       if(turn == 1){
           if(attack <= HeroAccuracy) MonsterHealth -= HeroStrength;
       }
       else{
           if(attack <= MonsterAccuracy) HeroHealth -= MonsterStrength;
       }
       turn = 3 - turn;
   }while(HeroHealth > 0 && MonsterHealth > 0)
   if(HeroHealth > 0) return HeroHealth;
   else return 0;
}

/* Part - 2 : Step 1 */
string weapon, defense_item, monster;
HeroHealth = 50;

cout << "Choose your weapon: sword, axe or dagger ?";
getline (cin, weapon);
if(strcmp(weapon, "sword") == 0){
   HeroStrength = 8;
   HeroAccuracy = 70;
}
else if(strcmp(weapon, "axe") == 0){
   HeroStrength = 10;
   HeroAccuracy = 50;
}
else if(strcmp(weapon, "dagger") == 0){
   HeroStrength = 4;
   HeroAccuracy = 95;
}

cout << "Choose the type of Monster: massive, sneaky or fast ?";
getline (cin, monster);
if(strcmp(monster, "massive") == 0){
   MonsterHealth = 100;
   MonsterStrength = 40;
   MonsterAccuracy = 15;
}
else if(strcmp(monster, "sneaky") == 0){
   MonsterHealth = 10;
   MonsterStrength = 30;
   MonsterAccuracy = 75;
}
else if(strcmp(monster, "fast") == 0){
   MonsterHealth = 75;
   MonsterStrength = 5;
   MonsterAccuracy = 99;
}

cout << "Choose your defense item: platemail, shield or headband ?";
getline (cin, defense_item);
if(strcmp(defense_item, "platemail") == 0){
   HeroHealth += 25;
}
else if(strcmp(defense_item, "shield") == 0){
   MonsterStrength -= 2;
}
else if(strcmp(defense_item, "headband") == 0){
   MonsterAccuracy -= 10;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote