Jump to content
  • Advertisement
Sign in to follow this  
Meta Adam

My program. was(Wierd Errors in this program.)

This topic is 5152 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
functions which belong to the class can access even the private members of that class :)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
I forgot which c library is rand in?

edit: and it's

int i = rand()%43;

and that will make i a random num between 0 and 43?

Share this post


Link to post
Share on other sites
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.)

Share this post


Link to post
Share on other sites
hmm, it prints the same, heres my code:

#include<iostream>
#include<cstdlib>
using namespace std;
int main() {
int i = rand()%20;
for(int x=0; x<10; x++) {
srand(x);
cout<<i<<endl;
}
return 0;
}

and my output is 10 1's.
maybe I dont understand modulus?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!