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

Started by
41 comments, last by Meta Adam 19 years, 3 months ago
wont that return an error though, because level is private?

edit: tried it and guess not, but I dont understand why
Meta AdamOne of a million noob C++ programmers.
Advertisement
functions which belong to the class can access even the private members of that class :)
"It's better to regret something you've done than to regret something you haven't done."
so even when the function is called outside, it is still a member of the class, so its alright.
Meta AdamOne of a million noob C++ programmers.
yup
"It's better to regret something you've done than to regret something you haven't done."
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.
Hee yay, I'm relearning things! =) Thanks for all your guys help!
Meta AdamOne of a million noob C++ programmers.
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
Meta AdamOne of a million noob C++ programmers.
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?
Meta AdamOne of a million noob C++ programmers.
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.)
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?
Meta AdamOne of a million noob C++ programmers.

This topic is closed to new replies.

Advertisement