numbers1-4
----------
you could write them as a function instead
e.g.
int getRandom(int max) { return rand() % max; }
then in your program you can have a local variable
1 2 3 4
|
randomanimal() {
...
numbers2 = getRandom(7);
...
| |
and so on.
design
------
It is generally better to put your definitions in the .cpp file instead
of having them in the header. When you look at a class for the first time
you want to see what functions are there, not how the implementation
looks like. If you then are interested you look in the .cpp file.
It is also recommended to put your classes/functions in a namespace
that way you keep things together and do not pollute the global namespace.
e.g.
1 2 3 4 5 6 7 8 9 10 11 12
|
namespace mygame
{
class animal {
...
}
void randomanimal() {
...
}
...
}
| |
You may also want to lose the global functions and make them member
functions in some class instead, then declare those animals you have
as member variables in that class instead of having extern animal lion etc.