wont that return an error though, because level is private?
edit: tried it and guess not, but I dont understand why
My program. was(Wierd Errors in this program.)
so even when the function is called outside, it is still a member of the class, so its alright.
Exactly! Private members of the class can only be accessed by other members of the class. This includes variables and functions! Public members can be access outside of the class, which is why all of your input and output methods are public. If those were private, you would not be able to call them from outside of another class method.
Okay I have my person and my monster classes now,
I'll make 1 simple fight, and then I should have some more questions. Lol
I'll make 1 simple fight, and then I should have some more questions. Lol
I forgot which c library is rand in?
edit: and it's
and that will make i a random num between 0 and 43?
edit: and it's
int i = rand()%43;
and that will make i a random num between 0 and 43?
stdlib.h
For things like this, use google. Simply type in "man rand()", and the unix man page should come up, which generally contains the necessary library.
And yes. The Modulus operator tells you the remainder when you divide by that number. For example, 7%2 is 1. It is [0,n) (aka, [0,n-1] with integers), where n is what you divide by. It must be this, because you cannot have a remainder equal or greater than what you are dividing by, or it would not be part of the remainder (as in, it would be divisible again.)
For things like this, use google. Simply type in "man rand()", and the unix man page should come up, which generally contains the necessary library.
And yes. The Modulus operator tells you the remainder when you divide by that number. For example, 7%2 is 1. It is [0,n) (aka, [0,n-1] with integers), where n is what you divide by. It must be this, because you cannot have a remainder equal or greater than what you are dividing by, or it would not be part of the remainder (as in, it would be divisible again.)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement