Im making a pokemon game and i ned to use the "charmander.basehp=65" in the equation for the health stat in "void pokemonshealth()", how would i do that?
Where are the variables hpiv, hpev and level declared?
You can't make the assignment charmander.basehp=65; outside of a function.
A class constructor may be helpful here.
i know that but that is not the question i left all trivial variables out i just need to know how to use the "charmander.basehp=65" in this equation. the other informatrion is there i just decided against writing it out in my post because it has nothing to do with my question.
assigned how do you mean if i declare it somewhere in the code either global or local it can be used in the equation?
also i need to have the program randomly generate a number between 1 and 31 and assign it as a pokemons iv can you explain how to generate random numbers better to me?
To generate a number from 1 to 31 (inclusive) randomly try: 1+rand()%31;.
I don't understand your 1st question. charmander was declared globally in my code above so it can be used in any function. You haven't given an equation for calculating hp state (another mystery variable).
i was just wondering where the charmander.basehp=65; would have to be declared to be included into void pokemonshealth()
so i only need 1+rand()%31 and nothing else because i though i would have to seed the rng?
just for a little insight im new to c++ and im making the function "void pokemonshealth()" and i am going to have that function randomly generate the iv then use that and a pokemons basehp stat to calculate its general stat for health. so i will have multiple pokemon using "void pokemonshealth()" to get calculate their stat for hp.
You should be able to call the function after making the assignment:
1 2 3 4 5 6 7 8
pokemon charmander;// declared globally
int main
{
charmander.basehp=65;
charmander.pokemonshealth();// assuming that all the other "trivial variables...not relevant to my question" have been assigned as well.
// other code
return 0;
}
Yes, it's a good idea to seed the "rng".
Be sure to #include<ctime>
Then seed the rng with a single call to srand((unsigned)time(0)); before the first call to rand().