Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Dice Question

This topic is 5644 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

I got help the other day from a tutor and while trying to compile the program at home, it turns out that I am missing 2 headers from the library. Is there a way I can avoid including the 2 headers "dice.h" and "bool.h" The program should run 1000 games of dice. a) How many games are won on the first roll, second roll, 20th roll and after the 20th roll? b) How many games are lost on the first, second, 20th and after the 20th roll? c) What are the chances of winning at dice? d) what is the average lenght of a game of dice? <-- I have not done this part Here''s the source code I ''ve got:

#include <dice.h>
#include <iostream.h>
#include <bool.h>

int  rollDice();
bool getPoint(int point);
bool winGame();

dice die(6);  

	int k, gamesWon = 0, gamesToPlay;
	double percWon;
	cout << "Enter number of games to play ---> ";
	cin >> gamesToPlay;
	for (k=0; k    


Share this post

Link to post
Share on other sites
It looks like "dice" is declared in "dice.h" so you won''t be able to get around using it, unless you just declare dice in that same file. It looks like all dice does is have a member function called roll() that returns a random number. So you could add something like this:

class dice
dice(int n) { m_num = n; srand(time(NULL)); }

int roll() { return ((rand()%m_num)+1);

int m_num;

If you add that to the beginning of the file, then you can get rid of "dice.h" and "bool.h".

Share this post

Link to post
Share on other sites

  • 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!