1. First of all, there are better random number generators out there. You should learn about them. But since you are using rand...
2. The srand (random number seed function) should only be called 1 time in the entire program. Call it in main() or have a static function in your Die class that calls it, and call that function in main. DO NOT call it every time you call roll.
3. Die::roll() is supposed to return an int. You do not return anything.
4. Your definition of Die::roll() (line 6 of dice.cpp) doe not provide a return type. It MUST match the declaration from dice.h
5. Line 9 is nonsensical. You want to assign the result of
rand()%4+1
to a variable. Instead you are trying to assign it to a recursive call to roll() (which makes no sense). Declare a variable here:
int result = rand() % 4 + 1;
and then do something with the result. (Hint: consider comment #3)
6. It is better to have functions do 1 thing only. So, I would recommend having roll() return the value (as declared in the header), and let the caller (in this case main()) print it or whatever.
7. In order to call roll(), you need to declare an object or type Die, and call roll() on that object:
1 2
|
Die d;
int result = d.roll();
|
8. Generally file names reflect the classes that they define. So, better names for your files would be Die.h and Die.cpp.