#include <dice.h>
#include <iostream.h>
#include <bool.h>
int rollDice();
bool getPoint(int point);
bool winGame();
dice die(6);
main()
{
int k, gamesWon = 0, gamesToPlay;
double percWon;
cout << "Enter number of games to play ---> ";
cin >> gamesToPlay;
for (k=0; k
Dice Question
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:
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:
If you add that to the beginning of the file, then you can get rid of "dice.h" and "bool.h".
class dice{public: dice(int n) { m_num = n; srand(time(NULL)); } ~dice(); int roll() { return ((rand()%m_num)+1);private: int m_num;};
If you add that to the beginning of the file, then you can get rid of "dice.h" and "bool.h".
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement