I'm really struggling with the setMonster() function, I'm getting super mixed and messed up.
Instruction:
setMonster()
This function takes the Monster variable passed and will assign the monster’s name to the name property in the Monster struct. This is done by calling randomNameGenerator() and assigning the function’s string return to the monster’s name. The monster’s combatPower is assigned as a random number between 1 – 450. When these two properties are assigned, return the entire instance of monster with a return statement.
randomNameGenerator()
Variables:
An array of names of type string initialized to a constant 25 elements and the following string list (feel free to copy and paste this list below into your code):
{
"Charmander", "Bulbasaur", "Squrtile", "Pidgey", "Pikachu", "Sandshrew", "Zubat", "Mankey", "Abra","Magikarp", "Eevee", "Rattata", "Vulpix", "Scyther", "Jigglypuff", "Geodude", "Onix", "Staryu","Snorlax", "Mewtwo", "Oddish", "Caterpie","Spearow" , "Charizard", "Zapdos"
};
This function returns a string. It starts by seeding the random number generator with “srand(time(NULL)) and declare an array of type string called “names” set to 25 elements initialized with the above list. It will then randomly return an element containing a string, so that each time this function is called a random pokemon name appears. Please return a random number using “rand()” from 0 – 24 inside the element to return, which is a string. This function should be called from “setMonster()” to set the monster’s name.
Here's what I got so far:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
string setMonster(Monster[])
{
srand(time(NULL));
Monster names[25];
{
"Charmander", "Bulbasaur", "Squrtile", "Pidgey", "Pikachu", "Sandshrew",
"Zubat", "Mankey", "Abra", "Magikarp", "Eevee", "Rattata", "Vulpix", "Scyther",
"Jigglypuff", "Geodude", "Onix", "Staryu", "Snorlax", "Mewtwo", "Oddish", "Caterpie",
"Spearow", "Charizard", "Zapdos";
}
string Monster randomNameGenerator(Monster x);
{
Monster x;
{
randomNameGenerator(names[25]);
names[x] = rand() % 25;
}
return x;
}
Monster int CombatPower;
//CombatPower needs to be a rand() between 1-450 but how do I build the return statement to combine CombatPower and randomNameGenerator?
}
| |