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

MAIN SOIRCE FILE: Create a struct named Monster Inside the header file, create a

ID: 3860750 • Letter: M

Question

MAIN SOIRCE FILE: Create a struct named Monster Inside the header file, create a struct cased Monster Monster should have the following attributes: Name//of type string Combat Power//of type int Write the following functions: captureAttempt() Variables: chance of type int This function takes a Monster data type as an argument and returns a boolean true or false. The monster argument is to use the combatPower value to determine the chance of catching the pokemon. The chances of catching a pokemon depends upon how high the combatPower is. Use the following scale: if combatPower is less than 100, there is a 1 in 2 chance to capture if combatPower is greater than 99, there is a 1 in 4 chance to capture if combatPower is greater than 200, there is a 1 in 8 chance to capture

Explanation / Answer

PROGRAM CODE:

#include <iostream>

using namespace std;

struct Monster

{

string name;

int combatPower;

};

bool captureAttempt(Monster monster)

{

int chance = 0;

if(monster.combatPower < 100)

chance = rand()%1;

else if(monster.combatPower > 99)

chance = rand()%3;

else if(monster.combatPower > 200)

chance = rand()%7;

if(chance == 0)

return true;

else return false;

}

string randomNameGenerator()

{

string names[25] = {"Charmander", "Bulbasor", "Squrtile", "Pidgey", "Pikachu",

"Sandshrew", "Zubat", "Mankey", "Abra", "Magikarp",

"Eevee", "Rattata", "Vulpix", "Scyther", "Jigglypuff",

"Geodude", "Onix", "Staryu", "Snorlax", "Mewtwo",

"Oddish", "Caterpie", "Spearow", "Charizard", "Zapdos",};

return names[rand()%24];

}

Monster setMonster(Monster monster)

{

monster.name = randomNameGenerator();

monster.combatPower = rand()%450 + 1;

return monster;

}

int main() {

srand(time(NULL));

Monster monster;

char input;

bool didCatch = false;

int pokeballs = 5;

while(true)

{

pokeballs--;

monster = setMonster(monster);

didCatch = captureAttempt(monster);

if(didCatch)

{

cout<<"Gotcha! You caught the monster "<<monster.name<<"!"<<endl;

cout<<"Attempt to catch again? (Y?N): " ;

}

else

cout<<"broke free! Attempt to catch again? (Y/N): "<<endl;

cin>>input;

if(input == 'N' || input == 'n')

{

cout<<" Got away safely."<<endl;

exit(0);

}

if(pokeballs == 0)

{

cout<<" You do not have any pokeballs, so you ran and got away safely.";

exit(0);

}

else

{

cout<<" Remianing pokeballs: "<<pokeballs<<endl;

}

}

return 0;

}

OUTPUT: